You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "TennyZhuang (via GitHub)" <gi...@apache.org> on 2026/04/17 07:12:18 UTC
[PR] fix(core): prevent integer overflow/underflow in BytesRange conversions [opendal]
TennyZhuang opened a new pull request, #7398:
URL: https://github.com/apache/opendal/pull/7398
# Which issue does this PR close?
N/A — follow-up to #7397, fixing the same class of integer overflow bugs in `BytesRange`.
# Rationale for this change
`BytesRange` has multiple integer overflow/underflow sites that cause different behavior in debug vs release builds:
1. **`From<RangeBounds>` (lines 190, 194)**: `n + 1` overflows at `u64::MAX` for `Bound::Excluded` start and `Bound::Included` end — same bug class as #7397. `n - offset` underflows when end < start.
2. **`FromStr` (line 178)**: `end - start + 1` underflows when parsing malformed HTTP Range headers where `end < start` (e.g., "bytes=10-5"). This is **external input** from HTTP responses parsed across all service backends.
3. **`to_range()` / `to_range_as_usize()`**: `self.0 + size` overflows when offset + size > u64::MAX.
4. **`Display`**: `self.0 + size - 1` overflows for the same reason.
# What changes are included in this PR?
- `From<RangeBounds>`: Replace bare arithmetic with `checked_add`/`checked_sub` + `expect` (panics with clear message instead of silent wraparound in release)
- `FromStr`: Add validation that `end >= start` before computing size, returning a proper error
- `to_range()` / `to_range_as_usize()`: Use `checked_add` + `expect`
- `Display`: Use `checked_add` returning `fmt::Error` on overflow
- Add 4 new tests covering all edge cases
# Are there any user-facing changes?
- `FromStr` now returns an error for malformed ranges where end < start (previously would underflow)
- `From<RangeBounds>` now panics with a clear message at u64::MAX boundaries (previously: debug panic with generic overflow message / release silent wraparound)
- `Display` now returns `fmt::Error` on overflow (previously: debug panic / release wrong output)
# AI Usage Statement
This PR was authored with assistance from Claude (Anthropic), used for code review, bug identification, fix implementation, and test writing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): prevent integer overflow/underflow in BytesRange conversions [opendal]
Posted by "asukaminato0721 (via GitHub)" <gi...@apache.org>.
asukaminato0721 commented on PR #7398:
URL: https://github.com/apache/opendal/pull/7398#issuecomment-4353535381
seems conflict
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(core): prevent integer overflow/underflow in BytesRange conversions [opendal]
Posted by "asukaminato0721 (via GitHub)" <gi...@apache.org>.
asukaminato0721 merged PR #7398:
URL: https://github.com/apache/opendal/pull/7398
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org