Skip to content

fix(transfer): clamp window_len to remaining file bytes in load_window - #5569

Merged
oferchen merged 2 commits into
fix/uts-18-buffered-bounds-fail-loudfrom
fix/uts-18-window-len-clamp
Jun 11, 2026
Merged

oferchen merged 2 commits into
fix/uts-18-buffered-bounds-fail-loudfrom
fix/uts-18-window-len-clamp

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Root-cause completion of PR fix(transfer): turn buffered map_file out-of-range panic into Err #5566. PR fix(transfer): turn buffered map_file out-of-range panic into Err #5566 added fail-loud guards at the two panic sites in BufferedMap (copy_within in load_window, slice indexing in map_ptr) so a malformed zlib delta turns SIGABRT into InvalidData. Those guards stop the abort but reject legitimate transfers whose cached window state is internally consistent yet pessimistically rejected by the bounds check.
  • Surgical one-line clamp at the single window_len assignment site. load_window now records window_len = window_size.min(file_size - window_start), making the invariant "window_len <= buffer.len() and window_len <= file_size - window_start" locally provable at the source. All four untrusted callers (transfer_ops/token_loop.rs:179, transfer_ops/response.rs:254, receiver/transfer/sync.rs:572, delta_apply/applicator.rs:358) inherit the fix because they share the same load path.
  • Effect. A 48128-byte basis file paired with MAX_MAP_SIZE = 262144 (the production crash ratio) now completes successfully end-to-end: window_len clamps to 48128 instead of inheriting the requested max, and the subsequent full-file map_ptr returns Ok with all 48128 bytes - not the "exceeds buffer length" Err PR fix(transfer): turn buffered map_file out-of-range panic into Err #5566's guard would otherwise surface.

Test plan

  • New positive unit test load_window_clamps_window_len_to_remaining_file_bytes mirrors the production crash math (file=48128 bytes, MAX_MAP_SIZE=262144):
    • Opens a 48128-byte basis file with a 262144-byte window cap.
    • Calls map_ptr(0, 48128) (the public entry shared by all four untrusted callers).
    • Asserts the returned slice equals the full file payload.
    • Asserts window_len == 48128 (the file size), not 262144.
    • Asserts window_len <= buffer.len() (the load-path invariant).
    • Asserts a repeated full-file map_ptr hits the cached window and returns the same bytes.
  • PR fix(transfer): turn buffered map_file out-of-range panic into Err #5566's existing negative tests (map_ptr_slice_out_of_range_returns_err_not_panic, load_window_overlap_shrink_returns_err_not_panic) continue to pass: this PR does not relax the fail-loud guards, it only widens the legitimate-input path that reaches them.
  • 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-features covers map_file::buffered::tests (verified by CI nextest matrix).

@github-actions github-actions Bot added the bug Something isn't working label 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`.
@oferchen
oferchen merged commit c2e178b into fix/uts-18-buffered-bounds-fail-loud Jun 11, 2026
70 checks passed
@oferchen
oferchen deleted the fix/uts-18-window-len-clamp branch June 11, 2026 03:11
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
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant