Repository navigation
fix(protocol): guard read_varint against integer overflow on malformed input - #5874
Merged
Merged
Conversation
oferchen
force-pushed
the
fix/pull-varint-overflow-guard
branch
from
June 17, 2026 15:10
3ce03de to
1baf804
Compare
…d input Add explicit min_bytes validation to read_varlong so a fuzzer-found or caller-induced min_bytes==0 or min_bytes>8 surfaces as InvalidData instead of panicking on usize subtract underflow at `min - 1` or slice OOB at `initial[..min]`. The valid encodable range is 1..=8: upstream's `u.b` union is 9 bytes wide and at least one byte is the leading tag. upstream: io.c:1827 read_varlong() implicitly requires min_bytes >= 1 (it reads min_bytes including the leading tag and indexes b2[min_bytes-1] plus u.b[min_bytes + extra - 1]). Bound is upstream's `if (min_bytes + extra > (int)sizeof u.b)`. Add regression tests covering: - read_varlong with min_bytes==0 (underflow panic before guard) - read_varlong with min_bytes>8 (slice OOB before guard) - read_varint across the full 0xFC..=0xFF tag range (extra=5,5,6,6), each of which must surface InvalidData (matches upstream io.c:1809 "Overflow in read_varint()") No wire-protocol behavior change for legitimate inputs. Crosses with PULL-VARINT (#4345) and CI-MASTER-FUZZ filter-fuzzer crashes.
oferchen
force-pushed
the
fix/pull-varint-overflow-guard
branch
from
June 17, 2026 15:20
1baf804 to
3151947
Compare
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…d input (#5874) Add explicit min_bytes validation to read_varlong so a fuzzer-found or caller-induced min_bytes==0 or min_bytes>8 surfaces as InvalidData instead of panicking on usize subtract underflow at `min - 1` or slice OOB at `initial[..min]`. The valid encodable range is 1..=8: upstream's `u.b` union is 9 bytes wide and at least one byte is the leading tag. upstream: io.c:1827 read_varlong() implicitly requires min_bytes >= 1 (it reads min_bytes including the leading tag and indexes b2[min_bytes-1] plus u.b[min_bytes + extra - 1]). Bound is upstream's `if (min_bytes + extra > (int)sizeof u.b)`. Add regression tests covering: - read_varlong with min_bytes==0 (underflow panic before guard) - read_varlong with min_bytes>8 (slice OOB before guard) - read_varint across the full 0xFC..=0xFF tag range (extra=5,5,6,6), each of which must surface InvalidData (matches upstream io.c:1809 "Overflow in read_varint()") No wire-protocol behavior change for legitimate inputs. Crosses with PULL-VARINT (#4345) and CI-MASTER-FUZZ filter-fuzzer crashes.
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
min_bytesvalidation toread_varlongso a fuzzer-found or caller-inducedmin_bytes == 0(ormin_bytes > 8) surfaces asInvalidDatainstead of panicking onusizesubtract underflow atmin - 1or slice OOB atinitial[..min]. The encodable range is1..=8: upstream'su.bunion is 9 bytes wide and at least one byte is the leading tag.min_bytes == 0,min_bytes > 8, and the full0xFC..=0xFFoverflow-tag range againstread_varint(each tag in that range maps toextra=5..6viaINT_BYTE_EXTRA, all exceedingMAX_EXTRA_BYTES=4).read_varintdecoder already errors gracefully on overflow tags; this PR makes the siblingread_varlongdecoder equally panic-proof against malformed caller input.Root cause
The slice-OOB panic in
read_varlongwas the highest-likelihood vector for theread_varint-family overflow reported under the daemon-pull failure (PULL-VARINT/ #4345 /UTS-V4.C). Crosses with the filter-fuzzer crashes (#4350CI-MASTER-FUZZ) which exercise the same call chain via flist decode.Upstream reference:
target/interop/upstream-src/rsync-3.4.1/io.c:1827read_varlong()implicitly requiresmin_bytes >= 1(it readsmin_bytesincluding the leading tag and indexesb2[min_bytes-1]plusu.b[min_bytes + extra - 1]). Upstream guard atio.c:1846isif (min_bytes + extra > (int)sizeof u.b)wheresizeof u.b == 9; we already mirror this for the upper-side check.Files touched
crates/protocol/src/varint/decode.rs—min_bytesrange guard inread_varlong, rustdoc updated.crates/protocol/src/varint/tests.rs— three new regression tests.Test plan
cargo fmt --all --checkcargo build -p protocol --lib