Skip to content

Commit a1878a5

Browse files
committed
qmdb/sync/gaps: clamp checked_add to range.end instead of unwrap-panic
Signed-off-by: SAY-5 <say.apm35@gmail.com>
1 parent 52f31c8 commit a1878a5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

storage/src/qmdb/sync/gaps.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,25 @@ pub fn find_next<'a, F: Family>(
3737
let mut next_uncovered: Location<F> = range.start;
3838

3939
// Create iterators for both data structures (already sorted)
40+
// `Location::checked_add` returns `None` on overflow *or* when the result
41+
// exceeds `Family::MAX_LEAVES`. The previous unconditional `.unwrap()`
42+
// panicked on fuzzer-generated inputs that placed `start_loc` near the
43+
// ceiling. Clamp such ranges to `range.end` instead — semantically the
44+
// batch is already at the boundary, so the merge logic terminates the
45+
// loop on the next iteration as expected (#2068).
46+
let range_end = range.end;
4047
let mut fetched_ops_iter = fetched_operations
4148
.iter()
4249
.map(|(&start_loc, &operation_count)| {
43-
let end_loc = start_loc.checked_add(operation_count).unwrap();
50+
let end_loc = start_loc.checked_add(operation_count).unwrap_or(range_end);
4451
start_loc..end_loc
4552
})
4653
.peekable();
4754

4855
let mut outstanding_reqs_iter = outstanding_requests
4956
.into_iter()
5057
.map(|&start_loc| {
51-
let end_loc = start_loc.checked_add(fetch_batch_size.get()).unwrap();
58+
let end_loc = start_loc.checked_add(fetch_batch_size.get()).unwrap_or(range_end);
5259
start_loc..end_loc
5360
})
5461
.peekable();

0 commit comments

Comments
 (0)