diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 00000000..188f1960 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +artifacts/ +corpus/ +target/ diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 00000000..0923993d --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "proc-macro2-fuzz" +version = "0.0.0" +authors = ["David Tolnay "] +edition = "2021" +publish = false + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +proc-macro2 = { path = ".." } + +[[bin]] +name = "parse_token_stream" +path = "fuzz_targets/parse_token_stream.rs" +test = false +doc = false + +[workspace] diff --git a/fuzz/fuzz_targets/parse_token_stream.rs b/fuzz/fuzz_targets/parse_token_stream.rs new file mode 100644 index 00000000..5b73e1b2 --- /dev/null +++ b/fuzz/fuzz_targets/parse_token_stream.rs @@ -0,0 +1,12 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; +use std::str; + +fuzz_target!(|bytes: &[u8]| { + if bytes.len() < 200 { + if let Ok(string) = str::from_utf8(bytes) { + _ = string.parse::(); + } + } +});