Xuanwo opened a new pull request, #8929:
URL: https://github.com/apache/opendal/pull/8929
# Which issue does this PR close?
N/A. Found while auditing `BytesRange` boundary arithmetic.
# Rationale for this change
`BytesRange::from<T: RangeBounds<u64>>` had two boundary bugs at `u64::MAX`,
diverging from `BytesRange::from_str`:
1. For `Bound::Included(n)`, computing
`n.saturating_add(1).saturating_sub(offset)` saturated at `u64::MAX` before
subtracting `offset`. When `n == u64::MAX` and `offset >= 1`, the resulting
size was off by one:
- `BytesRange::from(1..=u64::MAX)` produced `BytesRange::new(1,
Some(u64::MAX - 1))` instead of `BytesRange::new(1, Some(u64::MAX))`.
- `BytesRange::from(u64::MAX..=u64::MAX)` produced an empty
`BytesRange::new(u64::MAX, Some(0))` instead of `BytesRange::new(u64::MAX,
Some(1))`.
2. For `Bound::Excluded(u64::MAX)`, computing `u64::MAX.saturating_add(1)`
saturated back to `u64::MAX`, yielding a non-empty range
(`BytesRange::new(u64::MAX, None)` or `Some(1)`) instead of an empty range,
even though no `u64` value is strictly greater than `u64::MAX`.
# What changes are included in this PR?
- Return `BytesRange::new(u64::MAX, Some(0))` in `BytesRange::from` when
`start_bound` is `Bound::Excluded(u64::MAX)`.
- Compute inclusive end sizes as `if n < offset { 0 } else { (n -
offset).saturating_add(1) }`, matching `BytesRange::from_str` (saturating the
2^64-byte `0..=u64::MAX` range to `Some(u64::MAX)` while preserving exact sizes
for `1..=u64::MAX` and `u64::MAX..=u64::MAX`).
- Update and expand `u64::MAX` boundary unit tests, including parity
assertions against `BytesRange::from_str` and excluded-start/inverted boundary
cases.
# Are there any user-facing changes?
`BytesRange::from` now computes exact sizes for inclusive ranges ending at
`u64::MAX` with `offset >= 1` (matching `BytesRange::from_str`) and produces an
empty range for `Bound::Excluded(u64::MAX)`.
# Breaking changes
# AI Usage Statement
- Harness: pi coding agent (T3 Code)
- Model: Gemini 4 Neon
- Effort: high
- Role: Implemented the `BytesRange::from` boundary fix and unit tests,
checked remaining `BytesRange` methods for `u64::MAX` edge cases, and verified
formatting, clippy, unit tests, doc tests, and rustdoc. The human author
remains accountable for every submitted claim and change.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]