Skip to content

Commit e740de6

Browse files
authored
Merge pull request #3472 from qingshi163/fix-slice-overflow
fix #3468 SaturatedSliceIter overflow
2 parents 9fb7070 + 296afbc commit e740de6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

vm/src/builtins/slice.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ impl SaturatedSliceIter {
368368

369369
impl Iterator for SaturatedSliceIter {
370370
type Item = usize;
371+
371372
fn next(&mut self) -> Option<Self::Item> {
372373
if self.len == 0 {
373374
return None;
374375
}
375376
self.len -= 1;
376377
let ret = self.index as usize;
377-
self.index += self.step;
378+
// SAFETY: if index is overflowed, len should be zero
379+
self.index = self.index.wrapping_add(self.step);
378380
Some(ret)
379381
}
380382
}

0 commit comments

Comments
 (0)