From 4207faab09300ed7a2c91638cae787b967ff6442 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 24 Jun 2023 19:40:47 -0700 Subject: [PATCH] Fix overflow in delimiter_of_raw_string at end of input --- src/parse.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index 9bf5bd0..6c5cb41 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -468,22 +468,20 @@ fn cooked_byte_string(mut input: Cursor) -> Result { } fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> { - let mut n = 0; for (i, byte) in input.bytes().enumerate() { match byte { b'"' => { - n = i; - break; + if i > 255 { + // https://github.com/rust-lang/rust/pull/95251 + return Err(Reject); + } + return Ok((input.advance(i + 1), &input.rest[..i])); } b'#' => {} - _ => return Err(Reject), + _ => break, } } - if n > 255 { - // https://github.com/rust-lang/rust/pull/95251 - return Err(Reject); - } - Ok((input.advance(n + 1), &input.rest[..n])) + Err(Reject) } fn raw_byte_string(input: Cursor) -> Result {