From 640c103c0a2b92f7f2a49cfc0721577f40aa90e0 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Mon, 12 Sep 2022 01:01:11 -0700 Subject: Add fuzz testing Closes GH-7. --- .gitignore | 3 +++ fuzz/Cargo.toml | 25 +++++++++++++++++++++++++ fuzz/fuzz_targets/micromark.rs | 16 ++++++++++++++++ readme.md | 5 +++++ 4 files changed, 49 insertions(+) create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/micromark.rs diff --git a/.gitignore b/.gitignore index 0e0f1b9..b40bec5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ coverage/ target commonmark-data.txt unicode-data.txt +fuzz/target +fuzz/corpus +fuzz/artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..3c19003 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "micromark-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.micromark] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "micromark" +path = "fuzz_targets/micromark.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/micromark.rs b/fuzz/fuzz_targets/micromark.rs new file mode 100644 index 0000000..f4d2927 --- /dev/null +++ b/fuzz/fuzz_targets/micromark.rs @@ -0,0 +1,16 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +extern crate micromark; + +fuzz_target!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + let _ = micromark::micromark(s); + let _ = micromark::micromark_with_options( + s, + µmark::Options { + constructs: micromark::Constructs::gfm(), + ..micromark::Options::default() + }, + ); + } +}); diff --git a/readme.md b/readme.md index ac22d1c..c8ed452 100644 --- a/readme.md +++ b/readme.md @@ -372,6 +372,11 @@ The following scripts are useful when working on this project: ```sh cargo doc --document-private-items ``` +- fuzz: + ```sh + cargo install cargo-fuzz + cargo +nightly fuzz run micromark + ``` ### Version -- cgit