diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index 498380af3c9b..d9ab06bfd544 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -137,7 +137,24 @@ pub fn instantiate_with_config( Err(_) if !known_valid => return, Err(e) => panic!("failed to compile module: {:?}", e), }; - let linker = dummy_linker(&mut store, &module); + let linker = match dummy_linker(&mut store, &module) { + Ok(linker) => linker, + Err(e) => { + eprintln!("Warning: failed to create host imports: {:?}", e); + + // Currently the only error we want to allow here is ones where we + // ran out of resources creating imports. For example memory + // creation may not succeed if the host is running low on resources. + // + // Other errors, however, are bugs in creation of the host resource. + let string = e.to_string(); + assert!( + string.contains("Insufficient resources") + && string.contains("exceeds memory limits") + ); + return; + } + }; match linker.instantiate(&mut store, &module) { Ok(_) => {} @@ -227,7 +244,13 @@ pub fn differential_execution( // in and with what values. Like the results of exported functions, // calls to imports should also yield the same values for each // configuration, and we should assert that. - let linker = dummy_linker(&mut store, &module); + let linker = match dummy_linker(&mut store, &module) { + Ok(linker) => linker, + Err(e) => { + eprintln!("Warning: failed to create host imports: {:?}", e); + continue; + } + }; // Don't unwrap this: there can be instantiation-/link-time errors that // aren't caught during validation or compilation. For example, an imported @@ -397,7 +420,10 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) { }; let store = store.as_mut().unwrap(); - let linker = dummy_linker(store, module); + let linker = match dummy_linker(store, module) { + Ok(linker) => linker, + Err(_) => continue, + }; // Don't unwrap this: there can be instantiation-/link-time errors that // aren't caught during validation or compilation. For example, an imported diff --git a/crates/fuzzing/src/oracles/dummy.rs b/crates/fuzzing/src/oracles/dummy.rs index 648b0f0ec064..24ee1e406e6b 100644 --- a/crates/fuzzing/src/oracles/dummy.rs +++ b/crates/fuzzing/src/oracles/dummy.rs @@ -1,48 +1,49 @@ //! Dummy implementations of things that a Wasm module can import. +use anyhow::Result; use std::fmt::Write; use wasmtime::*; /// Create a set of dummy functions/globals/etc for the given imports. -pub fn dummy_linker<'module, T>(store: &mut Store, module: &Module) -> Linker { +pub fn dummy_linker<'module, T>(store: &mut Store, module: &Module) -> Result> { let mut linker = Linker::new(store.engine()); linker.allow_shadowing(true); for import in module.imports() { match import.name() { Some(name) => { linker - .define(import.module(), name, dummy_extern(store, import.ty())) + .define(import.module(), name, dummy_extern(store, import.ty())?) .unwrap(); } None => match import.ty() { ExternType::Instance(ty) => { for ty in ty.exports() { linker - .define(import.module(), ty.name(), dummy_extern(store, ty.ty())) + .define(import.module(), ty.name(), dummy_extern(store, ty.ty())?) .unwrap(); } } other => { linker - .define_name(import.module(), dummy_extern(store, other)) + .define_name(import.module(), dummy_extern(store, other)?) .unwrap(); } }, } } - linker + Ok(linker) } /// Construct a dummy `Extern` from its type signature -pub fn dummy_extern(store: &mut Store, ty: ExternType) -> Extern { - match ty { +pub fn dummy_extern(store: &mut Store, ty: ExternType) -> Result { + Ok(match ty { ExternType::Func(func_ty) => Extern::Func(dummy_func(store, func_ty)), ExternType::Global(global_ty) => Extern::Global(dummy_global(store, global_ty)), ExternType::Table(table_ty) => Extern::Table(dummy_table(store, table_ty)), - ExternType::Memory(mem_ty) => Extern::Memory(dummy_memory(store, mem_ty)), + ExternType::Memory(mem_ty) => Extern::Memory(dummy_memory(store, mem_ty)?), ExternType::Instance(instance_ty) => Extern::Instance(dummy_instance(store, instance_ty)), ExternType::Module(module_ty) => Extern::Module(dummy_module(store.engine(), module_ty)), - } + }) } /// Construct a dummy function for the given function type @@ -86,8 +87,8 @@ pub fn dummy_table(store: &mut Store, ty: TableType) -> Table { } /// Construct a dummy memory for the given memory type. -pub fn dummy_memory(store: &mut Store, ty: MemoryType) -> Memory { - Memory::new(store, ty).unwrap() +pub fn dummy_memory(store: &mut Store, ty: MemoryType) -> Result { + Memory::new(store, ty) } /// Construct a dummy instance for the given instance type. @@ -414,7 +415,7 @@ mod tests { #[test] fn dummy_memory_import() { let mut store = store(); - let memory = dummy_memory(&mut store, MemoryType::new(Limits::at_least(1))); + let memory = dummy_memory(&mut store, MemoryType::new(Limits::at_least(1))).unwrap(); assert_eq!(memory.size(&store), 1); }