Skip to content

Commit 91705f1

Browse files
committed
fix(encode): assert virtual position bound in borrowed skip-path
prime_hash_table_for_range_borrowed stores virtual [dict][input] positions with the same dict.region_len() base_offset as start_matching_borrowed_dict, but lacked that path's u32-bound validation. Add a debug_assert so test/direct-call misuse that overflows u32 fails loudly at the source; production is already gated by the frame compressor's borrowed_eligible check.
1 parent 792df34 commit 91705f1

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

zstd/src/encoding/simple/fast_matcher.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,12 @@ impl FastKernelMatcher {
13061306
// match what the dual-base dict kernel reads from the main table; 0 when
13071307
// no dict is attached.
13081308
let base_offset = self.dict.region_len();
1309+
debug_assert!(
1310+
base_offset
1311+
.checked_add(block_end)
1312+
.is_some_and(|v| v <= u32::MAX as usize),
1313+
"virtual position overflow: dict.region_len()={base_offset} + block_end={block_end} exceeds u32",
1314+
);
13091315
match self.hash_table.mls() {
13101316
4 => self.prime_hash_table_impl::<4>(base, backfill_start, last_hashable, base_offset),
13111317
5 => self.prime_hash_table_impl::<5>(base, backfill_start, last_hashable, base_offset),

0 commit comments

Comments
 (0)