From 550c774c1d87b713795d21aebe60ac21d802f525 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 26 Mar 2021 14:38:34 -0500 Subject: [PATCH] fuzz: Allow incompatible import types in instantiation (#2778) Yesterday fuzzing was switched to using a `Linker` to improve coverage when using module linking since we can fake instance imports with definitions of each individual item. Using a `Linker`, however, means that we can't necessarily instantiate all modules, such as (module (import "" "" (memory (;0;) 0 1)) (import "" "" (memory (;1;) 2))) As a result this just allows these sorts of "incompatible import type" errors when fuzzing to not trigger crashes. --- crates/fuzzing/src/oracles.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index c1f9b1e035..289e584de4 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -126,15 +126,27 @@ pub fn instantiate_with_config( match linker.instantiate(&module) { Ok(_) => {} - // Allow traps which can happen normally with `unreachable` or a timeout - Err(e) if e.downcast_ref::().is_some() => {} - // Allow resource exhaustion since this is something that our wasm-smith - // generator doesn't guarantee is forbidden. - Err(e) if e.to_string().contains("resource limit exceeded") => {} - // Also allow errors related to fuel consumption - Err(e) if e.to_string().contains("all fuel consumed") => {} - // Everything else should be a bug in the fuzzer - Err(e) => panic!("failed to instantiate {}", e), + Err(e) => { + let string = e.to_string(); + // Allow traps which can happen normally with `unreachable` or a + // timeout + if e.downcast_ref::().is_some() + // Allow resource exhaustion since this is something that + // our wasm-smith generator doesn't guarantee is forbidden. + || string.contains("resource limit exceeded") + // Also allow errors related to fuel consumption + || string.contains("all fuel consumed") + // Currently we instantiate with a `Linker` which can't instantiate + // every single module under the sun due to using name-based resolution + // rather than positional-based resolution + || string.contains("incompatible import type") + { + return; + } + + // Everything else should be a bug in the fuzzer + panic!("failed to instantiate {:?}", e); + } } }