Skip to content

Commit

Permalink
refactor(fuzz): Reject invalid UTF-8 data
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 15, 2024
1 parent f30de96 commit c0a772c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/toml_edit_fuzz/parse_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

use toml_edit::DocumentMut;

libfuzzer_sys::fuzz_target!(|data| {
libfuzzer_sys::fuzz_target!(|data: &[u8]| -> libfuzzer_sys::Corpus {
let Ok(data) = std::str::from_utf8(data) else {
return;
return libfuzzer_sys::Corpus::Reject;
};

println!("parsing: {data:?}");
let doc = match data.parse::<DocumentMut>() {
Ok(doc) => doc,
Err(err) => {
println!("{err}");
return;
return libfuzzer_sys::Corpus::Keep;
}
};
let toml = doc.to_string();
Expand All @@ -26,4 +26,5 @@ libfuzzer_sys::fuzz_target!(|data| {
);
let doc = doc.unwrap();
assert_eq!(doc.to_string(), toml);
libfuzzer_sys::Corpus::Keep
});

0 comments on commit c0a772c

Please sign in to comment.