Whoops: add fuzzers code.

This commit is contained in:
Nick Mathewson 2020-12-17 15:05:58 -05:00
parent 6f62f9c5dc
commit 5c92517245
3 changed files with 51 additions and 0 deletions

4
tor-consdiff/fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
target
corpus
artifacts

View File

@ -0,0 +1,26 @@
[package]
name = "tor-consdiff-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.3"
[dependencies.tor-consdiff]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
name = "compare_diffs"
path = "fuzz_targets/compare_diffs.rs"
test = false
doc = false

View File

@ -0,0 +1,21 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
let parts:Vec<_> = s.splitn(2, "=====\n").collect();
if parts.len() == 2 {
let orig = parts[0];
let diff = parts[1];
let out1 = tor_consdiff::apply_diff_trivial(orig, diff);
let out2 = tor_consdiff::apply_diff(orig, diff, None);
// dbg!(&out1);
// dbg!(&out2);
assert_eq!(out1.is_err(), out2.is_err());
match (out1, out2) {
(Ok(a), Ok(b)) => assert_eq!(a.to_string(),b.to_string()),
(_, _) => (),
}
}
}
});