Repository navigation
fix(transfer): never shrink BufferedMap buffer to avoid overlap data loss - #5588
Merged
Merged
Conversation
…loss PR #5569 review flagged a data-loss path in `BufferedMap::load_window`: `Vec::resize(window_size, 0)` truncates the buffer when a smaller window is requested. Under the overlap-shrink branch (new window near EOF after a full-size load), the bytes the overlap branch is about to relocate via `copy_within` are dropped before the copy runs, leading to either an out-of-bounds panic on the source range or silent corruption of the reused suffix once PR #5566's guard converts the panic to InvalidData. Upstream `fileio.c:236` `realloc_array` only grows the backing buffer. Mirror that invariant by replacing `buffer.resize(window_size, 0)` with `buffer.resize(window_size.max(buffer.len()), 0)`. The buffer becomes monotonically non-decreasing (capped at MAX_MAP_SIZE peak); `window_len` continues to bound the valid region so callers never see stale tail bytes. Picked the never-shrink fix over file-boundary-only shrink or shrink-and-reload because it is the smallest delta, matches upstream exactly, and has negligible memory cost in practice.
4 tasks
2 tasks
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
fix(transfer): never shrink BufferedMap buffer to avoid overlap data loss
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
UTS-18.j: extend URV-1 attestation with the basis-window panic chain discovered after the original codec-only audit cleared the file. Document the three follow-on regressions (window_len overstatement, buffer.resize overlap-shrink, bare slice index on misaligned chunk requests) and the remediation PRs (#5566, #5569, #5588, #5590, #5627). UTS-18.i: keep `compress-zlib-insert` out of the upstream-testsuite known-failures list so the workflow's wildcard run surfaces any regression as an UNEXPECTED FAIL. The cell already iterates `$suitedir/*.test`, so explicit wiring is the explanatory comment in `tools/ci/upstream_testsuite_known_failures.conf` plus the attestation-doc cross-reference.
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.
Summary
BufferedMap::load_windowcallsVec::resize(window_size, 0)which truncates the buffer when a smaller window is requested, dropping bytes the overlap branch is about to relocate viacopy_withinand either panicking on the now-out-of-bounds source range or (after PR fix(transfer): turn buffered map_file out-of-range panic into Err #5566's guard) surfacing the corruption asInvalidData.fileio.c:236whererealloc_arrayonly grows the backing buffer and never shrinks; the new window's valid extent is bounded bywindow_len, so retaining extra trailing capacity is harmless.buffer.resize(window_size.max(buffer.len()), 0)plus an upstream-citing comment and a positive regression test.Test plan
load_window_overlap_shrink_preserves_data(mirrors PR fix(transfer): clamp window_len to remaining file bytes in load_window #5569's positive-test style):map_ptr(0, 100)to fill the buffer towindow_len = 4096.map_ptr(3000, 1000)which triggers the overlap-shrink branch (aligned_start=2048, window_size=2952 < buffer.len()=4096) and would panic on the old code'scopy_within(2048..4096, 0)against a 2952-byte buffer.3000..4000.window_start == 2048andwindow_len == 2952(clamp to remaining file bytes).map_ptr(2048, 2952)matches file bytes2048..5000end-to-end, catching any silent truncation of the relocated suffix.window_slide_forward_reuses_overlaptest continues to pass (overlap reuse without shrink is unchanged -target_lenequals the existing buffer length).cargo fmt --all -- --check(verified by CI fmt+clippy gate).cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings(verified by CI).cargo nextest run -p transfer --all-featurescoversmap_file::tests::load_window_overlap_shrink_preserves_data(verified by CI nextest matrix).