diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 99a9a65eec..559250e06c 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -14,6 +14,7 @@ cranelift-codegen = "0.16.1" cranelift-wasm = "0.16.1" cranelift-native = "0.16.1" libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" } +wasmparser = { version = "0.17.2", default-features = false } # Prevent this from interfering with workspaces [workspace] diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs index 20c80f40b8..37ac91f2ef 100644 --- a/fuzz/fuzz_targets/compile.rs +++ b/fuzz/fuzz_targets/compile.rs @@ -2,26 +2,34 @@ #[macro_use] extern crate libfuzzer_sys; -extern crate cranelift; +extern crate cranelift_codegen; extern crate cranelift_wasm; extern crate cranelift_native; extern crate wasmtime_runtime; extern crate wasmtime_execute; +extern crate wasmparser; -use cranelift::settings; +use cranelift_codegen::settings; use cranelift_wasm::translate_module; +use wasmtime_runtime::{ModuleEnvironment, Module}; +use wasmparser::{validate}; fuzz_target!(|data: &[u8]| { + if !validate(data, None) { + return; + } let (flag_builder, isa_builder) = cranelift_native::builders().unwrap_or_else(|_| { panic!("host machine is not a supported target"); }); - let isa = isa_builder.finish(settings::Flags::new(&flag_builder)); - let mut runtime = wasmtime_runtime::Runtime::with_flags(isa.flags().clone()); - let translation = match translate_module(&data, &mut runtime) { - Ok(x) => x, + let isa = isa_builder.finish(settings::Flags::new(flag_builder)); + let mut module = Module::new(); + let mut runtime = ModuleEnvironment::new(&*isa, &mut module); + match translate_module(&data, &mut runtime) { + Ok(()) => (), Err(_) => return, }; - let _exec = match wasmtime_execute::compile_module(&translation, &*isa, &runtime) { + let translation = runtime.finish_translation(); + let _exec = match wasmtime_execute::compile_module(&*isa, &translation) { Ok(x) => x, Err(_) => return, }; diff --git a/test-all.sh b/test-all.sh index 4fb44d6a15..a250bc6579 100755 --- a/test-all.sh +++ b/test-all.sh @@ -75,10 +75,10 @@ if rustup toolchain list | grep -q nightly; then cargo +nightly install cargo-fuzz fi - fuzz_module="ffaefab69523eb11935a9b420d58826c8ea65c4c" + fuzz_module="8f0d725b20dcea52335cf521a5bb083833a5241f" ASAN_OPTIONS=detect_leaks=0 \ - cargo +nightly fuzz run fuzz_translate_module \ - "$topdir/fuzz/corpus/fuzz_translate_module/$fuzz_module" + cargo +nightly fuzz run compile \ + "$topdir/fuzz/corpus/compile/$fuzz_module" else echo "nightly toolchain not found, skipping fuzz target integration test" fi