Repository navigation
fix(core): validate suffix reads against their response length - #9220
Merged
Merged
Conversation
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
PsiACE
approved these changes
Nov 26, 2026
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Part of #9196.
Rationale for this change
A reused public
Readercaches theMetadatafrom its first observed open. If the object is overwritten to a different size,BufferStreamvalidates an unresolvedBytesRange::suffix(n)read against that cached length instead of the current open's response length.On
Memory, reading"ab"through aReadercaches length2. Overwriting the object with"abcdef"and readingBytesRange::suffix(4)on the sameReaderfails withUnexpected(reader got too much data, expecting2and receiving4) instead of returning"cdef". Reversing the overwrite ("abcdef"to"ab") fails withUnexpected(reader got too little data) instead of returning"ab". A freshReaderor raw reader succeeds in both directions.The suffix check uses metadata already returned by
open, so it adds nostatrequest.Reader::metadata()still exposes the first observed metadata.What changes are included in this PR?
core/core/src/types/read/buffer_stream.rs:StreamingReader::openrecordssuffix_object_lengthfrom the current suffix open'sRpReadfile metadata (rp.metadata().filter(|meta| meta.is_file()).map(Metadata::content_length)) before updatingReadContext.BufferStream::poll_nextcomputes the unresolved suffix expected length assuffix_size.min(length)usingsuffix_object_lengthwhen present.BufferStreamfalls back toReadContext::metadata()(cached file length). When neither length is available,suffix_sizeremains the upper bound (expected.or(this.suffix_size)) and shorter streams end at EOF.exact,limit, unbounded), raw completeness checks, caller bounds, and first-observedReader::metadata()semantics remain unchanged, with no newstatcalls.core/core/src/types/read/reader.rs:test_reader_read_suffix_after_overwritecovering both growth ("ab"->"abcdef", expecting"cdef") and shrink ("abcdef"->"ab", expecting"ab") on a reusedMemoryReaderwhile assertingReader::metadata()stays equal to the first read's metadata.Verification
The published head
0269965b3dhas the same patch as the independently reviewed00fedb594e. The reused-reader regression and 23 checksum integration tests passed during publication.00fedb594e(parentf0f5c89b19/ fix(services/etcd): advertise native recursive listing #9208): Onf0f5c89b19, the regression fails on growth (Unexpected, expect2, actual4) and a nativeMemoryprobe reproduces both growth (too much data) and shrink (too little data);00fedb594epasses the regression. Nine controlled response probes (including pre-composed operators withoutCompleteLayer) passed, confirming current-response length, cached fallback, zero-length responses, no extrastat, 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-coreClippy (--all-targets --all-features -- -D warnings), andcargo fmt --all -- --checkpassed.git merge-tree --write-treecombined00fedb594ewith feat(core,layers/checksum): add read checksum capability and verification layer #9209 head515a99f436(landed as7d83d20126) cleanly into tree82bc6095e7; all 15opendal-layer-checksumread integration tests andtest_reader_read_suffix_after_overwritepassed on that merged tree.00fedb594e, parent failure, candidate pass, the 9 controlled probes,opendal-coreandopendal-layer-retrysuites, 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, andFuturesAsyncReaderoverwrite behavior. Independently recomputed the feat(core,layers/checksum): add read checksum capability and verification layer #9209git merge-treeto the identical tree82bc6095e7without re-running the 15 checksum integration tests (relying on the implementation run above for those 15 tests).Are there any user-facing changes?
Reused
Readersuffix reads use the file length reported by the current open. For example, after an overwrite fromabtoabcdef,suffix(4)returnscdef.Breaking changes
AI Usage Statement
pi(via T3), Model:magpie/codex/gpt-6.2-sol, Effort:max, Role: Reproduced the nativeMemoryoverwrite failures, implemented theBufferStreamfix andtest_reader_read_suffix_after_overwriteregression in00fedb594e, 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.pi(via T3), Model:magpie/devin/swe-2-1, Effort:max, Role: Independently reviewed00fedb594e, 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.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.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 withscripts/release_impact.py check. The overwrite reproducer used the native Memory service.