Xuanwo opened a new pull request, #8974:
URL: https://github.com/apache/opendal/pull/8974
# Which issue does this PR close?
N/A.
# Rationale for this change
An audit of `core/services/oss` identified six locally verifiable protocol
and implementation bugs across presigning, batch/single deletion, listing,
version pagination, reading, and endpoint configuration:
1. `presign_write` unconditionally inserted `Content-Length: 0` into
`PresignedRequest::header()` because `OssCore::insert_metadata_headers` wrote
`size.unwrap_or_default()` even when `size` was `None`.
2. `OssDeleter::delete_batch` mapped the root key (`"/"`) under a non-root
`root` to `""` via `build_relative_path`, leaving `"/"` unmatched in `keys`
while pushing `("", op)` into `succeeded` and triggering `BatchDeleter`'s
`"batch delete result size mismatch"` error. In addition,
`OssDeleter::delete_once` treated every HTTP `404` as `Ok(())` without
inspecting the XML error code, swallowing `404 NoSuchBucket`.
3. `OssLister` and `OssObjectVersionsLister` copied `<ETag>` (a hex string
or `<hex>-<part_count>` for multipart uploads) into `Metadata::content_md5`,
which represents RFC 1864 Base64 MD5.
4. `OssObjectVersionsLister::next_page` set `ctx.done = false` whenever
`<IsTruncated>` was absent, did not stop when `NextKeyMarker` was empty, and
joined `key-marker` and `version-id-marker` with `" "` (`rsplit_once(" ")`),
corrupting pagination tokens for keys or version IDs containing spaces.
5. `OssReader::open` called `parse_into_metadata` directly instead of
`OssCore::parse_metadata`, dropping `x-oss-meta-*` user metadata and
`x-oss-version-id`; and `parse_error` left HTTP `401 Unauthorized` as
`ErrorKind::Unexpected` instead of permanent `ErrorKind::PermissionDenied`.
6. `OssBuilder::build` ignored `presign_addressing_style` (including invalid
values) whenever `presign_endpoint` was unset, and `OssBuilder::parse_endpoint`
performed a discarded `format!` allocation on every call.
# What changes are included in this PR?
- **Presign `Content-Length`**: Only set the `Content-Length` header in
`OssCore::insert_metadata_headers` when `size` is `Some(size)`, so
`presign_write` omits `Content-Length` while `PutObject` and `AppendObject`
continue sending exact lengths (including `0` for empty writes).
- **Batch delete root normalization & `404 NoSuchBucket`**:
- Normalize root-relative keys to `"/"` and guard against
unmatched/out-of-prefix `<Deleted>` entries in `OssDeleter::delete_batch` so
`succeeded.len() + failed.len()` always matches the input batch.
- Map `NoSuchBucket` to permanent `ErrorKind::ConfigInvalid` in
`parse_error`, and parse `404` responses in `OssDeleter::delete_once` so only
`ErrorKind::NotFound` (`NoSuchKey` / empty-body 404) is treated as idempotent
success.
- **Listing `content_md5`**: Stop populating `content_md5` from `<ETag>` in
`OssLister` and `OssObjectVersionsLister`, keeping `etag` only.
- **Object versions pagination**: Terminate
`OssObjectVersionsLister::next_page` unless `is_truncated == Some(true)` and
`next_key_marker` is non-empty, and join dual pagination markers with `'\0'`
(`split_once('\0')`) instead of `" "`.
- **Reader metadata & HTTP 401**: Parse `x-oss-version-id` alongside
`x-oss-meta-*` inside `OssCore::parse_metadata`, share it between
`OssBackend::stat` and `OssReader::open`, and map `StatusCode::UNAUTHORIZED` to
permanent `ErrorKind::PermissionDenied` in `parse_error`.
- **Presign addressing style & `parse_endpoint` cleanup**: Validate and
apply `presign_addressing_style` against `presign_endpoint.or(endpoint)`
whenever either option is set, reuse `endpoint` when both are unset, take
`Option<&str>` in `parse_endpoint`, and remove the unused `format!` expression.
- **Tests**: Add deterministic unit tests using mock `HttpTransport`
implementations and XML fixtures in `backend.rs`, `core.rs`, `deleter.rs`,
`lister.rs`, and `reader.rs` covering all six fixes.
# Are there any user-facing changes?
- `presign_write` no longer includes a spurious `content-length: 0` header.
- `list` and versioned `list` no longer populate `Metadata::content_md5`
from `<ETag>`.
- `delete` on a non-existent bucket (`404 NoSuchBucket`) now returns
`ErrorKind::ConfigInvalid` instead of `Ok(())`.
- `read` metadata now includes `x-oss-meta-*` user metadata and
`x-oss-version-id`, and HTTP `401 Unauthorized` responses now map to
`ErrorKind::PermissionDenied`.
- `presign_addressing_style` is now validated and applied even when
`presign_endpoint` is not explicitly configured.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Investigated the six protocol and implementation bugs in
`core/services/oss`, implemented the fixes, and wrote deterministic unit tests
with mock `HttpTransport` and XML fixtures. Verification was performed with
local unit tests, clippy, rustdoc, formatting, and spell checks (no live
Alibaba Cloud OSS bucket was used; changes that require live wire-contract
verification were intentionally excluded from this PR).
--
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]