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

   # Which issue does this PR close?
   
   None. Found during maintenance; no separate issue was filed.
   
   # Rationale for this change
   
   `HttpBody::read` in `core/core/src/types/http_transport/body.rs` had two 
correctness bugs:
   
   1. `oio::ReadStream::read` uses an empty `Buffer` as the EOF sentinel 
(`ReadStream::read_all` stops when `buf.is_empty()`). When the underlying HTTP 
stream yielded `Some(Ok(buf))` with an empty buffer, `HttpBody::read` returned 
`Ok(buf)` directly instead of continuing to poll, silently truncating 
subsequent chunks and bypassing `Content-Length` verification in 
`HttpBody::check()`.
   2. `HttpBody::read` only called `self.check()` when the stream ended 
(`None`) and updated `self.consumed += buf.len() as u64` without overflow 
checking. As a result, chunks exceeding the declared `Content-Length` were 
delivered to callers before EOF, and `self.consumed` could overflow `u64`.
   
   # What changes are included in this PR?
   
   - Loop in `HttpBody::read` to skip empty `Some(Ok(buf))` chunks until a 
non-empty chunk, an error, or `None` is received, preserving `wrap_stream_next` 
wrapping on every stream poll and running `self.check()` on `None`.
   - Update `self.consumed` using `checked_add` and immediately return a 
temporary `ErrorKind::Unexpected` (`too much data`) error if `self.consumed` 
exceeds the expected `Content-Length` or overflows `u64`.
   - Add unit tests in `core/core/src/types/http_transport/body.rs` covering 
leading/interleaved empty chunks, empty-only streams with non-zero and zero 
expected sizes, immediate rejection of oversized first/second chunks, `u64` 
overflow handling, and `wrap_stream_next` invocation across skipped empty 
chunks.
   
   # Are there any user-facing changes?
   
   HTTP response streams yielding empty chunks no longer truncate early or 
bypass `Content-Length` validation, and responses exceeding `Content-Length` 
now fail immediately with a temporary `ErrorKind::Unexpected` error instead of 
returning excess bytes before failing at EOF.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Reproduced both bugs with failing unit tests, implemented the 
`HttpBody::read` fix and regression tests, and ran local verification.
   


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