fix(encoding): encodeVarint() throws when value or buffer overflows#7149
Open
truffle-dev wants to merge 1 commit into
Open
fix(encoding): encodeVarint() throws when value or buffer overflows#7149truffle-dev wants to merge 1 commit into
encodeVarint() throws when value or buffer overflows#7149truffle-dev wants to merge 1 commit into
Conversation
`encodeVarint()` silently truncated when the input exceeded uint64 with the default 10-byte buffer: the loop bound `i <= Math.min(buf.length, MaxVarintLen64)` allowed an out-of-bounds write that was silently dropped by `Uint8Array`, and the final `num < MSBN` branch returned a tuple whose array length and reported offset disagreed. Add an explicit `num > MaxUint64` check before the loop and tighten the loop bound to `i < buf.length`. The trailing throw now reports the specific failure mode (buffer too small), since uint64 overflow is handled upfront. Closes denoland#7147
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7149 +/- ##
==========================================
- Coverage 94.61% 94.61% -0.01%
==========================================
Files 634 634
Lines 51843 51847 +4
Branches 9346 9348 +2
==========================================
+ Hits 49050 49053 +3
Misses 2218 2218
- Partials 575 576 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Fixes #7147.
encodeVarint()silently truncated when the input exceeded uint64 with the default 10-byte buffer. The loop boundi <= Math.min(buf.length, MaxVarintLen64)allowed an out-of-bounds write thatUint8Arraysilently dropped, and the finalnum < MSBNbranch returned a tuple whose array length and reported offset disagreed:The fix adds an explicit
num > MaxUint64check before the loop and tightens the loop bound toi < buf.length. The trailing throw now reports the specific failure mode (buffer too small), since uint64 overflow is caught upfront. Two regression tests cover both branches: a uint64-overflow input on the default buffer, and a valid uint64 value on a buffer that's too small.