-
Notifications
You must be signed in to change notification settings - Fork 1.2k
avro: bound VLQDecoder::long against overlong varints #10407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jefffrey
merged 3 commits into
apache:main
from
STiFLeR7:fix/10290-vlq-decoder-overlong-varint
Jul 25, 2026
+65
−9
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more branching to the loop makes me nervous...I'd like to see some benchmarks for this.
Perhaps something like
would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news on the benchmark front first:
Jefffrey's bot run above shows everyavro_readercase at ~1.00x ratio vs. base (both wall-clock and CPU), so the extra branch isn't measurable here.On the
checked_shlsuggestion specifically — I don't think it's equivalent, and I'd like to explain why before swapping it in.checked_shl(shift)only returnsNonewhen the shift amount itself is>= 64(i.e. an 11th+ continuation byte). It does not detect the case that actually matters at the boundary: on the 10th byte (shift == 63), a byte like0x7F(0b111_1111) shifted left by 63 doesn't overflow the shift-amount check at all — it just silently drops the top 6 bits of that byte's payload via ordinary<<semantics, andchecked_shlreturnsSome(...)with a truncated, wrong value rather thanNone. So that version would still decode a malformed 10-byte varint successfully, just to the wrongi64— which is the same "silently produce something instead of erroring" outcome @alamb's review on the stale #9887 was trying to move away from (discussion).The
byte >= 0x02check atshift == 63is what actually catches that: it mirrors the exact boundread_varint_arrayalready enforces for its own 10th byte a few lines below ((b < 0x02).then_some(...)), so this isn't a new convention, just applying the file's existing one to the stateful decoder too.Given the benchmarks come back flat, I'd lean toward keeping the explicit check for correctness — but happy to revisit if you'd rather accept the narrower
checked_shlguarantee (catches unbounded/DoS-style inputs, just not this one specific truncation case) for less branching.