Fix unsigned underflow in StackP4_16::pop_front - #1435
Merged
jafingerhut merged 1 commit intoJul 30, 2026
Conversation
sanket-jadhav-cse
force-pushed
the
fix-pop-front-underflow
branch
from
July 30, 2026 11:14
2322c27 to
e67b99d
Compare
ChrisDodd
approved these changes
Jul 30, 2026
Signed-off-by: Sanket Jadhav <sj546400@gmail.com>
sanket-jadhav-cse
force-pushed
the
fix-pop-front-underflow
branch
from
July 30, 2026 11:58
e67b99d to
3aa913c
Compare
jafingerhut
approved these changes
Jul 30, 2026
jafingerhut
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Apparently there are some C++ code style checks failing in CI. If you need help learning how to correct those, please ask. There should be some script you can run locally (I hope) that can modify the code formatting in a way that passes the style check, without having to do it manually.
Contributor
Author
|
@jafingerhut Thanks! I found the issue. It was a cpplint line-length check in the new test. I have fixed the formatting and force-pushed the update. Thanks for the review! |
Contributor
|
This fixes a crash: p4lang/p4c#5721 Very nice! |
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.
Summary
StackP4_16::pop_front(size_t num)computes the loop bound usingsize - num, wheresizeis an unsigned value. Whennumis greater than the stack size, this subtraction underflows, resulting in an invalid loop bound and out-of-bounds access.This change avoids the underflow by skipping the swap loop when
num >= sizeand directly invalidating the remaining headers. The existing behavior for valid inputs is preserved.Before
pop_front()computedsize - numunconditionally.pop_front()withnum > stack sizecaused unsigned integer underflow.std::vector::operator[]assertion failure.After
num < size.num >= size, all headers are invalidated directly.pop_front()safely handles requests larger than the stack size.Testing
HeaderStackP4_16Test.PopFrontLargeNumregression test.HeaderStackP4_16Test.PopFrontExactDepthboundary test.PopFrontLargeNumreproduces the failure with the original implementation.test_header_stackssuite successfully.test_switchtest due to a missing Pythonthriftdependency, which is unrelated to this change.