Skip to content

test(compress): add negative-bounds regression tests for BufferedMap::slice - #5703

Merged
oferchen merged 1 commit into
masterfrom
test/edg-panic-3-buffered-map-slice-bounds
Jun 11, 2026
Merged

oferchen merged 1 commit into
masterfrom
test/edg-panic-3-buffered-map-slice-bounds

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

EDG-PANIC.3 regression coverage. UTS-18.f replaced the bare slice indexing inside BufferedMap::map_ptr with a checked range + Err propagation, and UTS-18.g.2 clamped window_len in load_window. These unit tests pin every documented negative-bounds input shape against the contract: each MUST return Err, never panic. A future refactor that re-introduces a bare slice index will trip at least one of these tests.

The function lives in crates/transfer/src/map_file/buffered.rs (the task description's "compress crate / BufferedMap::slice" maps to transfer::map_file::BufferedMap::map_ptr here; the existing UTS-18 tests in the same file already exercise the load_window guard).

Cases shipped

All six cases requested by EDG-PANIC.3:

  • buffered_map_slice_rejects_offset_at_end - offset == file length, len == 1
  • buffered_map_slice_rejects_offset_past_end - offset > file length
  • buffered_map_slice_rejects_overflow - offset = u64::MAX - 1, len = 10 (saturation contract)
  • buffered_map_slice_rejects_extending_past_end - offset + len > size, neither alone exceeds
  • buffered_map_slice_allows_zero_length - len == 0 at offsets within and at end-of-file (positive control)
  • buffered_map_slice_allows_full_length_read - exactly file_size at offset 0 (positive control)

The pre-existing tests already in the file cover the inconsistent-state InvalidData paths (map_ptr_slice_out_of_range_returns_err_not_panic, load_window_overlap_shrink_returns_err_not_panic, load_window_clamps_window_len_to_remaining_file_bytes); these new tests cover the public-API negative-bounds inputs that should never reach the inner buffer index at all.

Test plan

  • cargo fmt --all clean
  • CI nextest green
  • CI fmt+clippy green

…slice

EDG-PANIC.3. UTS-18.f replaced the bare slice indexing inside
BufferedMap::map_ptr with a checked range + Err propagation, and
UTS-18.g.2 clamped window_len in load_window. Pin the contract with
explicit edge-case tests so a future refactor cannot regress the
fail-loud guard without tripping one of these:

- offset == file length, len == 1 (zero-length read past end)
- offset strictly past end of file
- offset + length overflows u64
- offset + length walks past end though neither alone exceeds
- len == 0 at any in-range offset (positive: empty Ok)
- exactly file-size read at offset 0 (positive: boundary Ok)
@oferchen
oferchen merged commit b759bca into master Jun 11, 2026
11 checks passed
@github-actions github-actions Bot added the test label Jun 11, 2026
@oferchen
oferchen deleted the test/edg-panic-3-buffered-map-slice-bounds branch June 12, 2026 14:39
oferchen added a commit that referenced this pull request Aug 24, 2026
…slice (#5703)

EDG-PANIC.3. UTS-18.f replaced the bare slice indexing inside
BufferedMap::map_ptr with a checked range + Err propagation, and
UTS-18.g.2 clamped window_len in load_window. Pin the contract with
explicit edge-case tests so a future refactor cannot regress the
fail-loud guard without tripping one of these:

- offset == file length, len == 1 (zero-length read past end)
- offset strictly past end of file
- offset + length overflows u64
- offset + length walks past end though neither alone exceeds
- len == 0 at any in-range offset (positive: empty Ok)
- exactly file-size read at offset 0 (positive: boundary Ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant