Skip to content

Commit

Permalink
Fix infinite while loop when buf size is less than 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kailes committed Nov 14, 2022
1 parent 84d6e80 commit ae2dbec
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/matchers/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ fn trim_start_whitespaces(mut buf: &[u8]) -> &[u8] {

/// Strip BOM at the beginning of the buffer.
fn trim_start_byte_order_marks(mut buf: &[u8]) -> &[u8] {
while !buf.is_empty() {
if buf.len() >= 3 {
match (buf[0], buf[1], buf[2]) {
(0xEF, 0xBB, 0xBF) => buf = &buf[3..], // UTF-8
(0xFE, 0xFF, _) => buf = &buf[2..], // UTF-16 BE
(0xFF, 0xFE, _) => buf = &buf[2..], // UTF-16 BE
_ => break,
}
while buf.len() >= 3 {
match (buf[0], buf[1], buf[2]) {
(0xEF, 0xBB, 0xBF) => buf = &buf[3..], // UTF-8
(0xFE, 0xFF, _) => buf = &buf[2..], // UTF-16 BE
(0xFF, 0xFE, _) => buf = &buf[2..], // UTF-16 BE
_ => break,
}
}
buf
Expand Down

0 comments on commit ae2dbec

Please sign in to comment.