From b3a921c761309ae00a51fe348d8a43adbc54b518 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Sat, 1 Apr 2023 03:09:26 -0700 Subject: Add `honggfuzz` as an alternative fuzzer Closes GH-55. Reviewed-by: Titus Wormer --- .gitignore | 2 ++ fuzz/Cargo.toml | 11 +++++++++-- fuzz/fuzz_targets/markdown.rs | 12 ------------ fuzz/fuzz_targets/markdown_honggfuzz.rs | 15 +++++++++++++++ fuzz/fuzz_targets/markdown_libfuzz.rs | 12 ++++++++++++ readme.md | 4 +++- 6 files changed, 41 insertions(+), 15 deletions(-) delete mode 100644 fuzz/fuzz_targets/markdown.rs create mode 100644 fuzz/fuzz_targets/markdown_honggfuzz.rs create mode 100644 fuzz/fuzz_targets/markdown_libfuzz.rs diff --git a/.gitignore b/.gitignore index b40bec5..b8732b4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ unicode-data.txt fuzz/target fuzz/corpus fuzz/artifacts +fuzz/hfuzz_target +fuzz/hfuzz_workspace \ No newline at end of file diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index c8f9850..6a50fd2 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,6 +10,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" +honggfuzz = "0.5" [dependencies.markdown] path = ".." @@ -19,7 +20,13 @@ path = ".." members = ["."] [[bin]] -name = "markdown" -path = "fuzz_targets/markdown.rs" +name = "markdown_libfuzz" +path = "fuzz_targets/markdown_libfuzz.rs" test = false doc = false + +[[bin]] +name = "markdown_honggfuzz" +path = "fuzz_targets/markdown_honggfuzz.rs" +test = false +doc = false \ No newline at end of file diff --git a/fuzz/fuzz_targets/markdown.rs b/fuzz/fuzz_targets/markdown.rs deleted file mode 100644 index ca6d86b..0000000 --- a/fuzz/fuzz_targets/markdown.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![no_main] -use libfuzzer_sys::fuzz_target; - -fuzz_target!(|data: &[u8]| { - if let Ok(s) = std::str::from_utf8(data) { - let _ = markdown::to_html(s); - let _ = markdown::to_html_with_options(s, &markdown::Options::gfm()); - let _ = markdown::to_mdast(s, &markdown::ParseOptions::default()); - let _ = markdown::to_mdast(s, &markdown::ParseOptions::gfm()); - let _ = markdown::to_mdast(s, &markdown::ParseOptions::mdx()); - } -}); diff --git a/fuzz/fuzz_targets/markdown_honggfuzz.rs b/fuzz/fuzz_targets/markdown_honggfuzz.rs new file mode 100644 index 0000000..6aa3c79 --- /dev/null +++ b/fuzz/fuzz_targets/markdown_honggfuzz.rs @@ -0,0 +1,15 @@ +use honggfuzz::fuzz; + +fn main() { + loop { + fuzz!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + let _ = markdown::to_html(s); + let _ = markdown::to_html_with_options(s, &markdown::Options::gfm()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::default()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::gfm()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::mdx()); + } + }); + } +} diff --git a/fuzz/fuzz_targets/markdown_libfuzz.rs b/fuzz/fuzz_targets/markdown_libfuzz.rs new file mode 100644 index 0000000..ca6d86b --- /dev/null +++ b/fuzz/fuzz_targets/markdown_libfuzz.rs @@ -0,0 +1,12 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + let _ = markdown::to_html(s); + let _ = markdown::to_html_with_options(s, &markdown::Options::gfm()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::default()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::gfm()); + let _ = markdown::to_mdast(s, &markdown::ParseOptions::mdx()); + } +}); diff --git a/readme.md b/readme.md index 8439439..9c9c580 100644 --- a/readme.md +++ b/readme.md @@ -268,7 +268,9 @@ The following bash scripts are useful when working on this project: * fuzz: ```sh cargo install cargo-fuzz - cargo +nightly fuzz run markdown + cargo install honggfuzz + cargo +nightly fuzz run markdown_libfuzz + cargo hfuzz run markdown_honggfuzz ``` ### Version -- cgit