From 110fe11fa8845ae6984e4bb70130a8da79447a71 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Fri, 24 Dec 2021 14:29:32 -0800 Subject: [PATCH] Add roundtrip-roundtrip fuzz target. --- fuzz/Cargo.toml | 6 ++++++ fuzz/fuzz_targets/roundtrip_roundtrip.rs | 14 ++++++++++++++ src/backend/final.rs | 1 + 3 files changed, 21 insertions(+) create mode 100644 fuzz/fuzz_targets/roundtrip_roundtrip.rs diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index f916814..81ef681 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -33,3 +33,9 @@ name = "roundtrip" path = "fuzz_targets/roundtrip.rs" test = false doc = false + +[[bin]] +name = "roundtrip_roundtrip" +path = "fuzz_targets/roundtrip_roundtrip.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/roundtrip_roundtrip.rs b/fuzz/fuzz_targets/roundtrip_roundtrip.rs new file mode 100644 index 0000000..20cdb64 --- /dev/null +++ b/fuzz/fuzz_targets/roundtrip_roundtrip.rs @@ -0,0 +1,14 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +use waffle::Module; + +fuzz_target!(|module: wasm_smith::Module| { + let _ = env_logger::try_init(); + log::debug!("original module: {:?}", module); + let orig_bytes = module.to_bytes(); + let parsed_module = Module::from_wasm_bytes(&orig_bytes[..]).unwrap(); + let roundtrip_bytes = parsed_module.to_wasm_bytes(); + let parsed_roundtrip_module = Module::from_wasm_bytes(&roundtrip_bytes[..]).unwrap(); + let _ = parsed_roundtrip_module.to_wasm_bytes(); +}); diff --git a/src/backend/final.rs b/src/backend/final.rs index a06ef09..9e04a35 100644 --- a/src/backend/final.rs +++ b/src/backend/final.rs @@ -169,6 +169,7 @@ pub fn produce_func_wasm( for operator in &body.operators { ctx.translate(operator, locations); } + wasm.operators.push(wasm_encoder::Instruction::End); wasm }