Repository navigation
fix(transfer): turn buffered map_file out-of-range panic into Err - #5566
Merged
Merged
Conversation
oferchen
force-pushed
the
fix/uts-18-buffered-bounds-fail-loud
branch
from
June 10, 2026 16:09
bb7b78b to
6ce80f5
Compare
5 tasks done
This was referenced Jun 10, 2026
oferchen
added a commit
that referenced
this pull request
Jun 10, 2026
Locks coverage of the UTS-18.f / UTS-18.g panic class in `transfer::map_file::BufferedMap` closed by PR #5566 (fail-loud `copy_within` + slice guards) and PR #5569 (`window_len` clamp at the source). Future regressions in `load_window` overlap-shrink or `map_ptr` slice bounds surface as nightly fuzz-coverage findings instead of waiting on a real crash report. - New libFuzzer target `fuzz/fuzz_targets/buffered_map.rs` drives both panic sites through the public `MapStrategy::map_ptr` entry. Six u64 LE words at the head of each input parametrize `(file_size, window_size, request_start/len, second_start/len)`; remaining bytes tile the synthetic basis file. Two `map_ptr` calls per input cover the empty-cache load path and the forward-overlap branch of `load_window`. - Three deterministic corpus seeds under `fuzz/corpus/buffered_map/`: `uts_18_overlap_shrink.bin` mirrors the production crash math (file=48128, MAX_MAP_SIZE=262144); `uts_18_truncated.bin` covers the 48-byte header boundary; `uts_18_zero_len.bin` covers the `len == 0` short-circuit. - `buffered_map` wired into `.github/workflows/fuzz-coverage-report.yml` matrix so the nightly run uploads lcov for the new target. - Audit note at `docs/audits/edg-panic-4-buffered-fuzz.md`.
This was referenced Jun 10, 2026
A malformed zlib delta stream could request a basis window whose
`reuse_len` (derived from the prior window extent) exceeds the resized
buffer length when the file tails off near EOF, or a slice whose `end`
walks past the cached window's backing buffer. Either case hit a bare
slice/copy_within and aborted the process with `SIGABRT`:
range end index 262144 out of range for slice of length 48128
`copy_within` and `&buf[..end]` panic on out-of-range; on untrusted
input the receiver should reject the basis with a typed I/O error
instead of taking the whole process down.
Adds a fail-loud guard at both slice sites in `BufferedMap`:
- `load_window` overlap branch: validate `src_offset.checked_add(reuse_len)`
against the resized buffer length before `copy_within`.
- `map_ptr` final slice: replace `&self.buffer[start..end]` with
`self.buffer.get(start..end).ok_or_else(...)`.
Both surface `io::ErrorKind::InvalidData` with the exact range and
buffer length, mirroring upstream rsync's behaviour of treating
basis-corruption as a recoverable transfer-level error.
Two regression tests fabricate inconsistent window state and assert
`map_ptr` returns Err rather than panicking - the first targets the
map_ptr slice site, the second drives the load_window overlap-shrink
branch with the same ratio as the production crash.
The root-cause fix - extending the buffered window vs rejecting the
upstream request - is a follow-up. This PR closes the panic surface so
the test fails with a clean Err instead of aborting.
# Conflicts:
# crates/transfer/src/map_file/buffered.rs
UTS-18.g root-cause clamp: record window_len against file_size minus window_start so any state-fabrication path cannot leave window_len claiming more bytes than the file actually has. The clamp guarantees the UTS-18.f bounds checks never trip on legitimate input where the underlying file is smaller than MAX_MAP_SIZE. Adds the UTS-18.g positive regression: a file of 48128 bytes (the production crash size) with MAX_MAP_SIZE=262144 must complete successfully via map_ptr, with window_len clamped to 48128 rather than inheriting the 262144 max_window value. Also folds in the UTS-18.g.2 cargo fmt collapse of the map_ptr range-overflow format! call.
oferchen
force-pushed
the
fix/uts-18-buffered-bounds-fail-loud
branch
from
June 11, 2026 03:08
c2e178b to
579072c
Compare
This was referenced Jun 11, 2026
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…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.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Locks coverage of the UTS-18.f / UTS-18.g panic class in `transfer::map_file::BufferedMap` closed by PR #5566 (fail-loud `copy_within` + slice guards) and PR #5569 (`window_len` clamp at the source). Future regressions in `load_window` overlap-shrink or `map_ptr` slice bounds surface as nightly fuzz-coverage findings instead of waiting on a real crash report. - New libFuzzer target `fuzz/fuzz_targets/buffered_map.rs` drives both panic sites through the public `MapStrategy::map_ptr` entry. Six u64 LE words at the head of each input parametrize `(file_size, window_size, request_start/len, second_start/len)`; remaining bytes tile the synthetic basis file. Two `map_ptr` calls per input cover the empty-cache load path and the forward-overlap branch of `load_window`. - Three deterministic corpus seeds under `fuzz/corpus/buffered_map/`: `uts_18_overlap_shrink.bin` mirrors the production crash math (file=48128, MAX_MAP_SIZE=262144); `uts_18_truncated.bin` covers the 48-byte header boundary; `uts_18_zero_len.bin` covers the `len == 0` short-circuit. - `buffered_map` wired into `.github/workflows/fuzz-coverage-report.yml` matrix so the nightly run uploads lcov for the new target. - Audit note at `docs/audits/edg-panic-4-buffered-fuzz.md`.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
EDG-PANIC.1: workspace audit of bare slice indexing patterns on attacker-controlled buffers (protocol/transfer/checksums/compress). ~314 indexing sites reviewed; only the two known UTS-18 sites in BufferedMap surfaced as suspect, both with a fix in flight via PR #5566. All other indexing is bounds-checked on the prior line, backed by fixed-size [u8; N] arrays, min-clamped, or covered by a length-prefix or library contract. Findings written to docs/audits/edg-panic-1-bare-slice-indexing.md with follow-up items enumerated as future EDG-PANIC tasks. EDG-PANIC.3: pin the BufferedMap basis-slice bounds contract with five negative-bounds unit tests against map_ptr (the BufferedMap "slice" accessor): - offset past EOF returns Err - length overflow (usize::MAX) returns Err - u64::MAX offset returns Err - offset == file_size with non-zero len returns Err (offset == file_size with zero len is a legitimate empty slice) - range straddling EOF returns Err Each test asserts io::ErrorKind::UnexpectedEof so a future change that drops or weakens the saturating_add guard is caught at the test boundary. Mirrors the malformed delta stream attack surface UTS-18 root-caused (range end index N out of range for slice of length M aborting the process). Refs: #3891, #3893
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…l-loud fix(transfer): turn buffered map_file out-of-range panic into Err
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
crates/transfer/src/map_file/buffered.rs:144(self.buffer.copy_within(src_offset..src_offset + reuse_len, 0)) aborts the process withrange end index 262144 out of range for slice of length 48128when a malformed zlib delta drives the overlap branch ofload_windowagainst a resized buffer that cannot hold the prior window's claimed extent. A sibling site atmap_ptr(&self.buffer[start..end]) carries the same panic surface.transfer_ops/token_loop.rs:179(and twin sites intransfer_ops/response.rs:254,receiver/transfer/sync.rs:572,delta_apply/applicator.rs:358) pass(offset, bytes_to_copy)derived from a token'sblock_idx * block_length. A malicious or corrupted basis stream can driveblock_idxinto a range where the cached window's claimed extent no longer matches the resized buffer.BufferedMapnow validate the range before indexing and returnio::ErrorKind::InvalidDatawith the exact out-of-range pair and buffer length.copy_withinis preceded by achecked_add+ length check;map_ptr's final slice usesslice::get(..). The errors propagate up throughmap_ptr->token_reader.see_token-> the transfer loop and map to upstream rsync's basis-corruption exit-code path.SIGABRT+ core dump.Test plan
map_ptr_slice_out_of_range_returns_err_not_panicfabricates a cached window state withwindow_len > buffer.len()and assertsmap_ptr(128, 64)returnsInvalidDatawith128..192and32in the message (stripped-down ratio of the production crash).load_window_overlap_shrink_returns_err_not_panicdrives the overlap-shrink branch directly withwindow_start=0, window_len=1500, max_window=1024sosrc_offset+reuse_len=1500walks past the resized 1024-byte buffer; asserts Err, not panic.compress-zlib-insertnow surfaces a typedInvalidDataerror and the process exits with the standard transfer error code instead ofSIGABRT.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(verified by CI nextest matrix).