Skip to content

Commit dc2347c

Browse files
committed
Fix unsoundness of peek_ahead in iter.rs
1 parent 380f130 commit dc2347c

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/iter.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ impl<'a> Bytes<'a> {
4343

4444
#[inline]
4545
pub fn peek_ahead(&self, n: usize) -> Option<u8> {
46-
// SAFETY: obtain a potentially OOB pointer that is later compared against the `self.end`
47-
// pointer.
48-
let ptr = self.cursor.wrapping_add(n);
49-
if ptr < self.end {
46+
if n < self.len() {
5047
// SAFETY: bounds checked pointer dereference is safe
51-
Some(unsafe { *ptr })
48+
Some(unsafe { *self.cursor.add(n) })
5249
} else {
5350
None
5451
}

0 commit comments

Comments
 (0)