Skip to content

Commit

Permalink
iter::slice_skip remove possibility of underflow in debug_assert
Browse files Browse the repository at this point in the history
`self.cursor.sub(skip)` must point inside the allocation of this object or this is UB, not to mention the possibility that if `skip` if very large self.cursor.sub(skip) may underflow and fail to trigger the debug_assertion.
  • Loading branch information
hkBst committed Dec 2, 2024
1 parent 390a6d3 commit 9802aa5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'a> Bytes<'a> {
/// implies a skip of at most 3).
#[inline]
pub unsafe fn slice_skip(&mut self, skip: usize) -> &'a [u8] {
debug_assert!(self.cursor.sub(skip) >= self.start);
debug_assert!(skip <= self.cursor.offset_from(self.start) as usize);
let head = slice_from_ptr_range(self.start, self.cursor.sub(skip));
self.commit();
head
Expand Down

0 comments on commit 9802aa5

Please sign in to comment.