Fuzz wasmparser (#47)
This commit is contained in:
parent
483736b1bd
commit
31a70aaa8d
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
});
|
Loading…
Reference in New Issue