Skip to content

Commit ed26084

Browse files
authored
Merge pull request #715 from epage/fuzz
fix(parser): Ensure error spans are valid for escape sequences
2 parents 90471b0 + f4f7eb1 commit ed26084

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/toml_edit/src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ impl TomlError {
2626
let raw = String::from_utf8(raw.to_owned()).expect("original document was utf8");
2727

2828
let offset = error.offset();
29+
let offset = (0..=offset)
30+
.rev()
31+
.find(|index| raw.is_char_boundary(*index))
32+
.unwrap_or(0);
33+
2934
let mut indices = raw[offset..].char_indices();
3035
indices.next();
3136
let len = if let Some((index, _)) = indices.next() {

crates/toml_edit/tests/testsuite/invalid.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,12 @@ fn text_error_span() {
227227
let actual = &input[err.span().unwrap()];
228228
assert_eq!(actual, "");
229229
}
230+
231+
#[test]
232+
fn fuzzed_68144_error_span() {
233+
let input = "\"\\ᾂr\"";
234+
let err = input.parse::<toml_edit::DocumentMut>().unwrap_err();
235+
dbg!(err.span());
236+
let actual = &input[err.span().unwrap()];
237+
assert_eq!(actual, "ᾂ");
238+
}

0 commit comments

Comments
 (0)