Repository navigation
test(compress): add negative-bounds regression tests for BufferedMap::slice - #5703
Merged
Merged
Conversation
…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)
3 tasks
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)
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
EDG-PANIC.3 regression coverage. UTS-18.f replaced the bare slice indexing inside
BufferedMap::map_ptrwith a checked range +Errpropagation, and UTS-18.g.2 clampedwindow_leninload_window. These unit tests pin every documented negative-bounds input shape against the contract: each MUST returnErr, 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 totransfer::map_file::BufferedMap::map_ptrhere; the existing UTS-18 tests in the same file already exercise theload_windowguard).Cases shipped
All six cases requested by EDG-PANIC.3:
buffered_map_slice_rejects_offset_at_end- offset == file length, len == 1buffered_map_slice_rejects_offset_past_end- offset > file lengthbuffered_map_slice_rejects_overflow- offset = u64::MAX - 1, len = 10 (saturation contract)buffered_map_slice_rejects_extending_past_end- offset + len > size, neither alone exceedsbuffered_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
InvalidDatapaths (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 --allclean