Skip to content

Commit

Permalink
Fix use of byte count instead of char count.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethiraric committed Oct 20, 2024
1 parent e925308 commit e6c4d04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions parser/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,8 +1775,9 @@ impl<T: Input> Scanner<T> {
}

// We need to manually update our position; we haven't called a `skip` function.
self.mark.col += line_buffer.len();
self.mark.index += line_buffer.len();
let n_chars = line_buffer.chars().count();
self.mark.col += n_chars;
self.mark.index += n_chars;

// We can now append our bytes to our `string`.
string.reserve(line_buffer.as_bytes().len());
Expand Down
11 changes: 11 additions & 0 deletions parser/tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,14 @@ fn fuzz_2() {
let s = str::from_utf8(raw_input).unwrap();
let _ = run_parser(s);
}

#[test]
fn fuzz_3() {
// Span mismatch when parsing with `StrInput` and `BufferedInput`.
// In block scalars, there was a section in which we took the byte count rather than the char
// count to update the index. The issue didn't happen with `StrInput` as the buffer was always
// full and the offending code was never executed.
let raw_input: &[u8] = &[124, 13, 32, 210, 180, 65];
let s = str::from_utf8(raw_input).unwrap();
let _ = run_parser(s);
}

0 comments on commit e6c4d04

Please sign in to comment.