Xuanwo opened a new pull request, #8892:
URL: https://github.com/apache/opendal/pull/8892
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements. You can link an issue to this PR using the GitHub syntax. For
example `Closes #123` indicates that this PR will close issue #123.
-->
N/A.
# Rationale for this change
This PR fixes two range-handling bugs in `opendal-service-http`:
1. **Silent data corruption when a server responds `200 OK` to a ranged
`GET`:** `HttpReader::open` accepted `StatusCode::OK |
StatusCode::PARTIAL_CONTENT` unconditionally. Under RFC 9110 section 14.2, a
server that ignores `Range` responds with `200 OK` and the complete
representation starting at byte 0. Accepting `200 OK` for a non-full
`BytesRange` silently returned bytes starting at offset 0 (and/or extra bytes
beyond the requested slice).
2. **Empty `Range:` header for unrepresentable `BytesRange` values:**
`BytesRange::to_header()` returns an empty string when `offset + size`
overflows `u64` or when `size == Some(0)`. `HttpCore::http_get_request` checked
`!range.is_full()` and unconditionally inserted `Range: <empty>` into the
outgoing request (and presigned GET requests) instead of failing locally.
# What changes are included in this PR?
- `core/services/http/src/reader.rs`:
- Restrict `StatusCode::OK` acceptance in `HttpReader::open` to
`range.is_full()` (covering both `..` and `0..`, neither of which sends a
`Range` header).
- For non-full ranged reads that receive `200 OK`, return a permanent
`ErrorKind::Unexpected` error with response and range context, dropping the
response body without draining it so large objects are not buffered into memory.
- Keep `StatusCode::PARTIAL_CONTENT` handling unchanged.
- `core/services/http/src/core.rs`:
- In `HttpCore::http_get_request`, reject non-full ranges whose
`BytesRange::to_header()` is empty with a permanent
`ErrorKind::RangeNotSatisfied` error (with `offset` and optional `size`
context) before building or sending the HTTP request.
- `core/services/http/src/{core,reader}.rs` &
`core/services/http/Cargo.toml`:
- Add unit tests covering `200 OK` rejection on ranged reads (with and
without `Content-Length`, ensuring the body is not drained), `200 OK`
acceptance for full reads (`..` and `0..`), `206 Partial Content` ranged reads,
and local rejection of overflowing / zero-length ranges for both direct reads
and presigned reads.
# Are there any user-facing changes?
- Ranged HTTP reads against servers that ignore the `Range` header and reply
with `200 OK` now return a permanent `ErrorKind::Unexpected` error instead of
silently returning bytes from offset 0.
- HTTP reads and presigned GET requests with unrepresentable `BytesRange`
values (e.g., overflowing `offset + size` or zero-length ranges) now fail
locally with `ErrorKind::RangeNotSatisfied` instead of sending an empty
`Range:` header.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Investigated both range-handling bugs in `opendal-service-http`,
implemented the fixes in `HttpCore::http_get_request` and `HttpReader::open`,
and added unit tests using mock `HttpTransport` implementations. Assumptions
affecting review: strict rejection of `200 OK` on all non-full ranges
(including `0..N`) assumes callers expect RFC 9110 `206 Partial Content`
semantics for ranged reads rather than client-side slicing of a full `200 OK`
body.
--
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]