Skip to content

Commit

Permalink
Support cargo-fuzz
Browse files Browse the repository at this point in the history
Two targets to start with:

1) decompression into a growable writer,
2) decompression into a fixed-size buffer,

The latter finds dropbox/rust-brotli#213
quite quickly.
  • Loading branch information
ctz authored and danielrh committed May 27, 2024
1 parent c5c93d9 commit 12a68ac
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
32 changes: 32 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "brotli-decompressor-fuzz"
version = "0.0.0"
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.brotli-decompressor]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "decompress_into_vec"
path = "fuzz_targets/decompress_into_vec.rs"
test = false
doc = false

[[bin]]
name = "decompress_into_fixed"
path = "fuzz_targets/decompress_into_fixed.rs"
test = false
doc = false
13 changes: 13 additions & 0 deletions fuzz/fuzz_targets/decompress_into_fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_main]

extern crate libfuzzer_sys;

use std::io::Cursor;
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut input = Cursor::new(data);
let mut output_buf = [0u8; 2048];
let mut output = Cursor::new(&mut output_buf[..]);
let _ = brotli_decompressor::BrotliDecompress(&mut input, &mut output);
});
12 changes: 12 additions & 0 deletions fuzz/fuzz_targets/decompress_into_vec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_main]

extern crate libfuzzer_sys;

use libfuzzer_sys::fuzz_target;
use std::io::Cursor;

fuzz_target!(|data: &[u8]| {
let mut input = Cursor::new(data);
let mut output = Cursor::new(Vec::new());
let _ = brotli_decompressor::BrotliDecompress(&mut input, &mut output);
});

0 comments on commit 12a68ac

Please sign in to comment.