SFT-7485: bind the UR path sequence to the part it carries - #65
Open
Jacksper13 wants to merge 1 commit into
Open
Jacksper13 wants to merge 1 commit into
Jacksper13 wants to merge 1 commit into
Conversation
A multipart UR carries its sequence number and count twice, in the URI path and inside the CBOR part. Decoder::receive() parsed both and compared neither, then sized and stored from the inner pair, so the path could describe something other than what it carried. The encoder writes both from the same values - MultiPartDeserialized's Display renders the path out of fragment.sequence and fragment.sequence_count - so they agree for anything this library produced. Compare them before handing the part to the fountain, which is what allocates and mutates decoder state, and report both pairs in a new Error::InconsistentSequence. Caller-configurable maxima and structured heapless capacity errors are left for a separate change; they add public API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A multipart UR carries its sequence number and count twice — once in the URI path, once inside the CBOR part.
Decoder::receive()parsed both and compared neither, then sized and stored from the inner pair.The encoder always writes the two from the same values:
UR::MultiPartDeserialized'sDisplayrenders the path straight out offragment.sequence/fragment.sequence_count. So they agree for anything this library produced, and a disagreement means the path is describing something other than what it carries.receive()now binds them before the fountain sees the part:The check sits after the part is decoded — it has to be, the inner values are in the CBOR — but before
self.fountain.receive(), which is what allocates and mutates decoder state.Error::InconsistentSequencecarries both pairs, so a caller can say what it saw.The
_ =>arm is unreachable:is_multi_part()is checked at the top ofreceive(). It refuses rather than unwrapping, so the function has no panic of its own.Not in this change
The ticket also asks for caller-configurable maxima on message bytes, fragments, equation rows and queued parts, and for heapless capacity failures to become structured errors throughout. Those add public API and want their own review; this is the binding that stops path metadata and part contents disagreeing in the first place. Worth saying that the binding removes the route the ticket describes for reaching those limits with hidden values, but it does not itself impose a ceiling on an honestly-declared large message.
Tests
In
ur/src/ur/decoder.rs, each building its input by rewriting the path segment of a real encoder's output:1-1path — the case where a caller gating on the path sees two copies of one single part, and the two previously assembled into a message1-1pathto_string()/parse()path, still decodes to the original messageThe first three fail without the check.
SFT-7485