Skip to content

Commit 7b4f645

Browse files
jrey8343claude
andcommitted
Fix arithmetic overflow in next_match/next_match_back Kani abstractions
Replace kani::assume(a + w <= finger_back) with the overflow-safe form: assume a <= finger_back then w <= finger_back - a. This prevents usize overflow when a and w are both symbolic values (kani::any()). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 49b81b8 commit 7b4f645

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/core/src/str/pattern.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
488488
let a: usize = kani::any();
489489
let w = self.utf8_size();
490490
kani::assume(a >= self.finger);
491-
kani::assume(w <= self.finger_back); // avoid overflow
492-
kani::assume(a + w <= self.finger_back);
491+
kani::assume(a <= self.finger_back); // avoid overflow in a + w
492+
kani::assume(w <= self.finger_back - a);
493493
self.finger = a + w;
494494
Some((a, self.finger))
495495
} else {
@@ -627,8 +627,8 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
627627
let a: usize = kani::any();
628628
let w = self.utf8_size();
629629
kani::assume(a >= self.finger);
630-
kani::assume(w <= self.finger_back);
631-
kani::assume(a + w <= self.finger_back);
630+
kani::assume(a <= self.finger_back); // avoid overflow in a + w
631+
kani::assume(w <= self.finger_back - a);
632632
self.finger_back = a;
633633
Some((a, a + w))
634634
} else {

0 commit comments

Comments
 (0)