Skip to content

fix(core): validate suffix reads against their response length - #9220

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/publish-reader-suffix-response-length
Nov 26, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/publish-reader-suffix-response-length

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Part of #9196.

Rationale for this change

A reused public Reader caches the Metadata from its first observed open. If the object is overwritten to a different size, BufferStream validates an unresolved BytesRange::suffix(n) read against that cached length instead of the current open's response length.

On Memory, reading "ab" through a Reader caches length 2. Overwriting the object with "abcdef" and reading BytesRange::suffix(4) on the same Reader fails with Unexpected (reader got too much data, expecting 2 and receiving 4) instead of returning "cdef". Reversing the overwrite ("abcdef" to "ab") fails with Unexpected (reader got too little data) instead of returning "ab". A fresh Reader or raw reader succeeds in both directions.

The suffix check uses metadata already returned by open, so it adds no stat request. Reader::metadata() still exposes the first observed metadata.

What changes are included in this PR?

  • core/core/src/types/read/buffer_stream.rs:
    • StreamingReader::open records suffix_object_length from the current suffix open's RpRead file metadata (rp.metadata().filter(|meta| meta.is_file()).map(Metadata::content_length)) before updating ReadContext.
    • BufferStream::poll_next computes the unresolved suffix expected length as suffix_size.min(length) using suffix_object_length when present.
    • When that suffix response omits file length, BufferStream falls back to ReadContext::metadata() (cached file length). When neither length is available, suffix_size remains the upper bound (expected.or(this.suffix_size)) and shorter streams end at EOF.
    • Non-suffix paths (exact, limit, unbounded), raw completeness checks, caller bounds, and first-observed Reader::metadata() semantics remain unchanged, with no new stat calls.
  • core/core/src/types/read/reader.rs:
    • Add test_reader_read_suffix_after_overwrite covering both growth ("ab" -> "abcdef", expecting "cdef") and shrink ("abcdef" -> "ab", expecting "ab") on a reused Memory Reader while asserting Reader::metadata() stays equal to the first read's metadata.
  • Remaining boundary:
    • When a later suffix response omits file length after an overwrite, the fallback can still use a stale length and reject a valid suffix.

Verification

The published head 0269965b3d has the same patch as the independently reviewed 00fedb594e. The reused-reader regression and 23 checksum integration tests passed during publication.

  • Candidate 00fedb594e (parent f0f5c89b19 / fix(services/etcd): advertise native recursive listing #9208): On f0f5c89b19, the regression fails on growth (Unexpected, expect 2, actual 4) and a native Memory probe reproduces both growth (too much data) and shrink (too little data); 00fedb594e passes the regression. Nine controlled response probes (including pre-composed operators without CompleteLayer) passed, confirming current-response length, cached fallback, zero-length responses, no extra stat, and preserved raw/exact/limited/chunked/simulated-retry checks. opendal-core (550 unit tests, 166 doctests with 12 ignored), opendal-layer-retry (47 unit tests, 5 doctests), opendal-core Clippy (--all-targets --all-features -- -D warnings), and cargo fmt --all -- --check passed.
  • feat(core,layers/checksum): add read checksum capability and verification layer #9209 integration check (implementation run): git merge-tree --write-tree combined 00fedb594e with feat(core,layers/checksum): add read checksum capability and verification layer #9209 head 515a99f436 (landed as 7d83d20126) cleanly into tree 82bc6095e7; all 15 opendal-layer-checksum read integration tests and test_reader_read_suffix_after_overwrite passed on that merged tree.
  • Independent reviewer verification: Re-verified the GPG signature on 00fedb594e, parent failure, candidate pass, the 9 controlled probes, opendal-core and opendal-layer-retry suites, Clippy, and formatting on the two changed files. Authored and passed 6 additional probes covering chunked suffix revalidation after overwrite growth/shrink, overwrite to empty, metadata-free shrink, the heterogeneous metadata-omission residual, and FuturesAsyncReader overwrite behavior. Independently recomputed the feat(core,layers/checksum): add read checksum capability and verification layer #9209 git merge-tree to the identical tree 82bc6095e7 without re-running the 15 checksum integration tests (relying on the implementation run above for those 15 tests).

Are there any user-facing changes?

Reused Reader suffix reads use the file length reported by the current open. For example, after an overwrite from ab to abcdef, suffix(4) returns cdef.

Breaking changes

AI Usage Statement

  • Harness: pi (via T3), Model: magpie/codex/gpt-6.2-sol, Effort: max, Role: Reproduced the native Memory overwrite failures, implemented the BufferStream fix and test_reader_read_suffix_after_overwrite regression in 00fedb594e, and ran the controlled probes, core/retry suites, Clippy, formatting, and feat(core,layers/checksum): add read checksum capability and verification layer #9209 merge-tree checksum compatibility tests. Prepared and published the signed PR head and checked its merge preview.
  • Harness: pi (via T3), Model: magpie/devin/swe-2-1, Effort: max, Role: Independently reviewed 00fedb594e, re-verified signature, predecessor failure, controlled probes, core/retry suites, Clippy, and the feat(core,layers/checksum): add read checksum capability and verification layer #9209 merge-tree hash (82bc6095e7, without re-running the 15 merged-tree checksum tests), and authored 6 additional edge-case probes confirming chunked/empty/metadata-free behavior and the heterogeneous metadata-omission residual.
  • Harness: pi (via T3), Model: magpie/codex/gpt-6.2-astra, Effort: high, Role: Investigated refactor(core): deduplicate read completeness checks and suffix range revalidation #9196 read-completeness and suffix-revalidation boundaries that isolated this standalone suffix bug and coordinated implementation and review scope.
  • Harness: pi (via T3), Model: magpie/agy-cli/gemini-4-neon (Gemini 4 Neon), Effort: high, Role: Drafted the first public refactor(core): deduplicate read completeness checks and suffix range revalidation #9196 reply and this PR title and body from verified commits, evidence logs, and independent review findings, and validated the compatible-change declaration with scripts/release_impact.py check. The overwrite reproducer used the native Memory service.

A reused Reader retains the metadata from its first observed open.
An overwrite can change the object size, so that length can reject
a valid suffix from a later open.

Use the file length from the current suffix response when available.
Preserve the cached length fallback for responses without file metadata.

Refs #9196
@Xuanwo Xuanwo added the releases-note/fix The PR fixes a bug or has a title that begins with "fix" label Nov 26, 2026
@Xuanwo
Xuanwo requested a review from PsiACE November 26, 2026 23:29
@Xuanwo
Xuanwo merged commit 84b6297 into main Nov 26, 2026
95 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/publish-reader-suffix-response-length branch November 26, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants