fix(core): prevent integer overflow in parse_into_range for u64::MAX bounds#7397
Open
TennyZhuang wants to merge 2 commits intoapache:mainfrom
Open
fix(core): prevent integer overflow in parse_into_range for u64::MAX bounds#7397TennyZhuang wants to merge 2 commits intoapache:mainfrom
TennyZhuang wants to merge 2 commits intoapache:mainfrom
Conversation
…bounds `parse_into_range` uses `v + 1` to convert `Bound::Excluded` start and `Bound::Included` end bounds into a `Range<u64>`. When users pass `..=u64::MAX` or `(Bound::Excluded(u64::MAX), ..)`, this causes: - Panic in debug builds (integer overflow) - Silent wrap to 0 in release builds (incorrect range calculation) Both are user-triggerable through public Reader methods like `read()`, `read_into()`, `into_stream()`, `into_futures_async_read()`, and `into_bytes_stream()`, all of which accept `RangeBounds<u64>`. Fix: use `checked_add(1)` and return `ErrorKind::RangeNotSatisfied` when the bound value cannot be incremented. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dentiny
approved these changes
Apr 20, 2026
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.
Which issue does this PR close?
N/A — discovered via code review of boundary edge cases.
Rationale for this change
ReadContext::parse_into_rangeconvertsRangeBounds<u64>intoRange<u64>by adding 1 forBound::Excludedstart andBound::Includedend. When the bound value isu64::MAX, this causes:Both outcomes are wrong. Users can trigger this with ranges like
..=u64::MAXor(Bound::Excluded(u64::MAX), Bound::Unbounded).What changes are included in this PR?
v + 1withv.checked_add(1)for bothBound::Excludedstart andBound::Includedend inparse_into_rangeErrorKind::RangeNotSatisfiedon overflow instead of panicking or wrappingu64::MAXedge casesAre there any user-facing changes?
Ranges that previously caused a panic (debug) or silent incorrect behavior (release) now return a clear
RangeNotSatisfiederror.AI Usage Statement
This PR was authored with assistance from Claude (Anthropic), used for code review, bug identification, fix implementation, and test writing.