Skip to content

Commit

Permalink
Merge pull request #80 from kailes/master
Browse files Browse the repository at this point in the history
Fix infinite `while` loop when buf size is less than `3`
  • Loading branch information
bojand committed Jan 1, 2023
2 parents 84d6e80 + ae2dbec commit ef46e98
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/matchers/text.rs
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 ef46e98

Please sign in to comment.