Xuanwo opened a new pull request, #8990:
URL: https://github.com/apache/opendal/pull/8990

   # Which issue does this PR close?
   
   Related Issues: None.
   
   # Rationale for this change
   
   Three core read-range and HTTP range-parsing inconsistencies existed on 
`main`:
   
   1. **Streaming bounded range `offset + size` overflow 
(`BufferStream::create` and `PositionReader`)**: 
`ReadContext::parse_into_range` rejects bounded ranges where `offset + size` 
exceeds `u64::MAX` with `ErrorKind::RangeNotSatisfied`, but 
`BufferStream::create` only ran `parse_into_range` when `chunk` was configured. 
On the default non-chunked streaming path, an overflowing bounded range such as 
`BytesRange::new(u64::MAX, Some(2))` bypassed validation, causing 
`BytesRange::to_header()` to emit an empty `Range` header (which HTTP servers 
ignore per RFC 9110 §14.2 and serve from offset 0) and exposing unchecked 
`offset += n` addition in `PositionReader::read` and `PositionReadStream::read`.
   2. **Unchecked streaming suffix read lengths (`BufferStream`)**: Unlike 
`StreamReader::read` and chunked reads, non-chunked streaming suffix reads in 
`BufferStream` enforced neither an upper bound against the requested suffix 
size nor exact completeness against known `RpRead` file `content_length`. Exact 
bounded reads also deferred oversized-chunk checks until EOF instead of failing 
before yielding extra bytes.
   3. **RFC 9110 `1*DIGIT` strictness in range header parsing 
(`BytesRange::from_str` and `BytesContentRange::from_str`)**: Both parsers 
relied directly on `u64::from_str`, which accepts leading `'+'` signs (e.g., 
`"bytes=+0-+5"`, `"bytes +0-+5/+10"`), violating RFC 9110 §14.1.2 and §14.4 
(`1*DIGIT`) and diverging from `http_util::parse_content_length`.
   
   # What changes are included in this PR?
   
   - `core/core/src/types/read/buffer_stream.rs`:
     - Reject bounded forward ranges with overflowing `offset + size` in 
`BufferStream::create` with `ErrorKind::RangeNotSatisfied` before branching on 
`chunk`.
     - Track `suffix_size` on non-chunked streaming suffix reads 
(`limit.is_none()`); reject oversized chunks immediately without yielding them 
(for both exact bounded and streaming suffix reads) and verify EOF completeness 
against `suffix_size.min(meta.content_length())` when file metadata is present 
on `ReadContext`.
   - `core/core/src/raw/oio/read/position_read.rs`:
     - Reject bounded ranges where `offset + size` overflows `u64::MAX` in 
`PositionReader::open` and `PositionReader::read` with 
`ErrorKind::RangeNotSatisfied`.
     - Use `checked_add` when advancing offsets in `PositionReader::read` and 
`PositionReadStream::read`, returning `ErrorKind::RangeNotSatisfied` and 
marking the stream done on overflow.
   - `core/core/src/types/bytes_range.rs` & 
`core/core/src/raw/http_util/bytes_content_range.rs`:
     - Validate that numeric components are non-empty ASCII digit sequences 
(`1*DIGIT`) before parsing as `u64`, rejecting leading `'+'` signs with 
`ErrorKind::Unexpected`.
   - Added unit tests covering bounded range overflow in `BufferStream` and 
`PositionReader`, unbounded offset overflow in `PositionReadStream`, streaming 
suffix truncation and over-delivery, immediate rejection of oversized exact 
bounded chunks, and leading `'+'` rejection in `BytesRange::from_str` and 
`BytesContentRange::from_str`.
   
   # Are there any user-facing changes?
   
   - Non-chunked streaming reads with an overflowing bounded `BytesRange` 
(`offset + size > u64::MAX`) now return `ErrorKind::RangeNotSatisfied`, 
matching chunked reads.
   - Non-chunked streaming suffix reads now reject oversized responses and 
truncated responses when file `content_length` is known, matching 
`StreamReader::read` and chunked reads.
   - `BytesRange::from_str` and `BytesContentRange::from_str` now reject 
leading `'+'` signs in range numbers per RFC 9110.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Verified the three read-range and header-parsing defects against 
`origin/main`, implemented the fixes and deterministic unit tests in 
`opendal-core`, and validated with core tests, clippy, formatting, and typo 
checks.
   


-- 
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]

Reply via email to