A few more small fuzzing fixes (#2770)

* Increase allowances for values when fuzzing

The wasm-smith limits for generating modules are a bit higher than what
we specify, so sync those up to avoid getting too many false positives
with limits getting blown.

* Ensure fuzzing `*.wat` files are in sync

I keep looking at `*.wat` files that are actually stale, so remove stale
files if we write out a `*.wasm` file and can't disassemble it.

* Enable shadowing in dummy_linker

Fixes an issues where the same name is imported twice and we generated
two values for that. We don't mind the error here, we just want to
ignore the shadowing errors.
This commit is contained in:
Alex Crichton
2021-03-25 18:44:04 -05:00
committed by GitHub
parent 8bb1f8adc9
commit 516a97b3f3
3 changed files with 15 additions and 6 deletions

View File

@@ -39,9 +39,13 @@ pub fn fuzz_default_config(strategy: wasmtime::Strategy) -> anyhow::Result<wasmt
.wasm_bulk_memory(true)
.wasm_reference_types(true)
.wasm_module_linking(true)
.max_instances(100)
.max_tables(100)
.max_memories(100)
// The limits here are chosen based on the default "maximum type size"
// configured in wasm-smith, which is 1000. This means that instances
// are allowed to, for example, export up to 1000 memories. We bump that
// a little bit here to give us some slop.
.max_instances(1100)
.max_tables(1100)
.max_memories(1100)
.strategy(strategy)?;
Ok(config)
}

View File

@@ -34,9 +34,13 @@ fn log_wasm(wasm: &[u8]) {
let name = format!("testcase{}.wasm", i);
std::fs::write(&name, wasm).expect("failed to write wasm file");
log::debug!("wrote wasm file to `{}`", name);
if let Ok(s) = wasmprinter::print_bytes(wasm) {
let name = format!("testcase{}.wat", i);
std::fs::write(&name, s).expect("failed to write wat file");
let wat = format!("testcase{}.wat", i);
match wasmprinter::print_bytes(wasm) {
Ok(s) => std::fs::write(&wat, s).expect("failed to write wat file"),
// If wasmprinter failed remove a `*.wat` file, if any, to avoid
// confusing a preexisting one with this wasm which failed to get
// printed.
Err(_) => drop(std::fs::remove_file(&wat)),
}
}

View File

@@ -6,6 +6,7 @@ use wasmtime::*;
/// Create a set of dummy functions/globals/etc for the given imports.
pub fn dummy_linker<'module>(store: &Store, module: &Module) -> Linker {
let mut linker = Linker::new(store);
linker.allow_shadowing(true);
for import in module.imports() {
match import.name() {
Some(name) => {