[Algorithm] Fix inverted trailer check condition in ForwardParser#15547
Open
niteshg97 wants to merge 3 commits into
Open
[Algorithm] Fix inverted trailer check condition in ForwardParser#15547niteshg97 wants to merge 3 commits into
niteshg97 wants to merge 3 commits into
Conversation
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.
Problem
ForwardParser::parse()inAlgorithm/include/Algorithm/Parser.hcontainsan inverted condition for trailer handling:
tailOffset = typesize<TrailerType>::size, so it is> 0precisely whena real
TrailerTypeis specified. The condition is completely inverted:TrailerTypeexists (tailOffset > 0),entry.traileris setto
nullptrand the user-suppliedcheckTrailercallback is never invoked.TrailerTypeisvoid(tailOffset == 0), the dead else-branch runsa no-op CheckTrailer specialisation that always returns
true.Consequence: frames with corrupt or invalid trailers are silently accepted
without any validation. No crash occurs, making this bug invisible without
dedicated tests.
Why existing tests did not catch this
test_forwardparser_header_and_trailerprovides acheckTrailerlambda butnever asserts it was actually called — it only checks payload bytes. The tests
passed even though the callback was completely bypassed.
Fix
Invert the condition (
tailOffset > 0→tailOffset == 0):Tests
Updated
test_forwardparser_header_and_trailer:checkTrailerinvocations and asserts it is called once per frame.frames[i].trailer != nullptrand correctflagsfields are extracted.Added
test_forwardparser_trailer_check_rejection:checkTrailerthat rejects the second frame.result == -1(format error) and thatinsertis never called.All existing tests (void-trailer, no-frames, format-error, reverse-parser)
are unaffected — they use
TrailerType = void(tailOffset == 0) and arehandled by the unchanged if-branch.