Fuzz wasmparser (#47)

This commit is contained in:
Sergey Pepyakin 2018-02-09 22:41:02 +03:00 committed by GitHub
parent 483736b1bd
commit 31a70aaa8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -11,6 +11,7 @@ cargo-fuzz = true
[dependencies]
wasmi = { path = ".." }
wabt = "0.1.7"
wasmparser = "0.14.1"
[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
@ -22,3 +23,7 @@ members = ["."]
[[bin]]
name = "load"
path = "fuzz_targets/load.rs"
[[bin]]
name = "load_wasmparser"
path = "fuzz_targets/load_wasmparser.rs"

View File

@ -0,0 +1,29 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate wasmi;
extern crate wasmparser;
use wasmparser::WasmDecoder;
fn run_wasmparser(data: &[u8]) -> bool {
let mut parser = wasmparser::ValidatingParser::new(data, None);
let result = loop {
match *parser.read() {
wasmparser::ParserState::Error(..) => break false,
wasmparser::ParserState::EndWasm => break true,
_ => (),
}
};
result
}
fn run_wasmi(data: &[u8]) -> bool {
wasmi::Module::from_buffer(data).is_ok()
}
fuzz_target!(|data: &[u8]| {
let wasmparser_success = run_wasmparser(data);
let wasmi_success = run_wasmi(data);
assert_eq!(wasmparser_success, wasmi_success);
});