Fix recursive destuffing in physical layer byte stuffing codec#7
Merged
Fix recursive destuffing in physical layer byte stuffing codec#7
Conversation
gertvdijk
commented
Apr 19, 2026
This was referenced Apr 19, 2026
Closed
jktjkt
suggested changes
Apr 19, 2026
Contributor
jktjkt
left a comment
There was a problem hiding this comment.
I was lazy and my test only included byte destuffing. Can you perhaps add another test for producing these byte-stuffed sequences?
Owner
Author
Actually I believe it was silly to have a separate I'll add a commit under this one to merge these two tests -- that should cover that I guess then? |
4e75957 to
33d6299
Compare
Merge the happy-path PhysicalCodec tests into a single parametrized test that checks both decode() and encode() from the same examples. This makes the physical-layer examples symmetrical, reduces duplicated test data, and lowers the chance that an encoding or decoding fix is only covered on one side.
The previous PhysicalCodec.decode() implementation used repeated replace() calls, which could inadvertently destuff newly created byte sequences again. This caused some valid frames to be decoded incorrectly. This changes the physical byte stuffing logic to a single-pass implementation for both decode() and encode(). Besides fixing an actual bug in decode(), this also removes the fragile ordering dependency from the encoding logic and adds validation for truncated or invalid stuffing sequences. Co-Authored-By: Gert van Dijk <github@gertvandijk.nl>
33d6299 to
0f9209a
Compare
Owner
Author
|
I couldn't find an actual bug in the encode() logic; it was just fragile I guess. I have reworded some things accordingly in the last force-push. |
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.
The previous PhysicalCodec.decode() implementation used repeated replace() calls, which could inadvertently destuff newly created byte sequences again. This caused some valid frames to be decoded incorrectly.
This changes the physical byte stuffing logic to a single-pass implementation for both decode() and encode().
Besides fixing an actual bug in decode(), this also removes the fragile ordering dependency from the encoding logic and adds validation for truncated or invalid stuffing sequences.
Original PR by @jktjkt in #6; this is a slightly reworked version using a generator and has been reworded.