From 8f4b8840c41aa62fd15b655f08f838b02e98ccdc Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Sun, 5 May 2019 19:42:48 +0200 Subject: [PATCH] png-afl: document usage and minor tweaks, fixes #132 --- png-afl/.gitignore | 1 + png-afl/Cargo.toml | 5 +++-- png-afl/README.md | 18 ++++++++++++++++++ png-afl/src/main.rs | 6 +++--- 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 png-afl/.gitignore create mode 100644 png-afl/README.md diff --git a/png-afl/.gitignore b/png-afl/.gitignore new file mode 100644 index 00000000..1fcb1529 --- /dev/null +++ b/png-afl/.gitignore @@ -0,0 +1 @@ +out diff --git a/png-afl/Cargo.toml b/png-afl/Cargo.toml index 310d6447..5f034397 100644 --- a/png-afl/Cargo.toml +++ b/png-afl/Cargo.toml @@ -4,7 +4,8 @@ version = "0.2.0" authors = ["Sergey Davidoff ", "Paul Grandperrin "] [dependencies] -afl = "0.4.0" +afl = "0.4.3" png = {path = "../"} - +[features] +fuzzing = [] diff --git a/png-afl/README.md b/png-afl/README.md new file mode 100644 index 00000000..720ffb8f --- /dev/null +++ b/png-afl/README.md @@ -0,0 +1,18 @@ + +## Build fuzzer binary + +RUSTFLAGS='-C codegen-units=1' cargo afl build + +NOTE: the RUSTFLAGS is only needed on Linux (and not if using gold linker), see https://github.com/rust-lang/rust/issues/53945 + + +## Run fuzzer + + cargo afl fuzz -m 200 -i fuzzing_seeds -o out target/debug/png-afl + +NOTE: -m 200 sets memory limit to 200 mb. afl defaults to 50 megabytes memory usage. If we would not increase it, many invocations will exit with SIGABRT and look like crashes. + + +### More info + +https://rust-fuzz.github.io/book/afl/tutorial.html diff --git a/png-afl/src/main.rs b/png-afl/src/main.rs index dc507dcf..b3b66130 100644 --- a/png-afl/src/main.rs +++ b/png-afl/src/main.rs @@ -1,3 +1,4 @@ +#[macro_use] extern crate afl; extern crate png; @@ -25,8 +26,7 @@ fn png_decode(data: &[u8]) -> Result<(png::OutputInfo, Vec), ()> { } fn main() { - afl::fuzz(|data| { - //afl::read_stdio_bytes(|data| { - png_decode(&data); + fuzz!(|data: &[u8]| { + let _ = png_decode(&data); }); }