Skip to content

Commit

Permalink
initial oss-fuzz integration. (rust-lang#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKorczynski authored Apr 15, 2021
1 parent f9e26de commit 7546110
Show file tree
Hide file tree
Showing 3 changed files with 45 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
24 changes: 24 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

[package]
name = "flate2-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
flate2 = { path = ".." }

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

[[bin]]
name = "fuzz_gz_roundtrip"
path = "fuzz_targets/fuzz_gz_roundtrip.rs"
test = false
doc = false
17 changes: 17 additions & 0 deletions fuzz/fuzz_targets/fuzz_gz_roundtrip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use flate2::write::GzEncoder;
use flate2::Compression;
use flate2::read::GzDecoder;
use std::io::prelude::*;


fuzz_target!(|data: &[u8]| {
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
encoder.write_all(data).unwrap();
let result = encoder.finish().unwrap();
let mut r = GzDecoder::new(&result[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == data);
});

0 comments on commit 7546110

Please sign in to comment.