Skip to content

Commit 516a97b

Browse files
authored
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.
1 parent 8bb1f8a commit 516a97b

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

crates/fuzzing/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ pub fn fuzz_default_config(strategy: wasmtime::Strategy) -> anyhow::Result<wasmt
3939
.wasm_bulk_memory(true)
4040
.wasm_reference_types(true)
4141
.wasm_module_linking(true)
42-
.max_instances(100)
43-
.max_tables(100)
44-
.max_memories(100)
42+
// The limits here are chosen based on the default "maximum type size"
43+
// configured in wasm-smith, which is 1000. This means that instances
44+
// are allowed to, for example, export up to 1000 memories. We bump that
45+
// a little bit here to give us some slop.
46+
.max_instances(1100)
47+
.max_tables(1100)
48+
.max_memories(1100)
4549
.strategy(strategy)?;
4650
Ok(config)
4751
}

crates/fuzzing/src/oracles.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ fn log_wasm(wasm: &[u8]) {
3434
let name = format!("testcase{}.wasm", i);
3535
std::fs::write(&name, wasm).expect("failed to write wasm file");
3636
log::debug!("wrote wasm file to `{}`", name);
37-
if let Ok(s) = wasmprinter::print_bytes(wasm) {
38-
let name = format!("testcase{}.wat", i);
39-
std::fs::write(&name, s).expect("failed to write wat file");
37+
let wat = format!("testcase{}.wat", i);
38+
match wasmprinter::print_bytes(wasm) {
39+
Ok(s) => std::fs::write(&wat, s).expect("failed to write wat file"),
40+
// If wasmprinter failed remove a `*.wat` file, if any, to avoid
41+
// confusing a preexisting one with this wasm which failed to get
42+
// printed.
43+
Err(_) => drop(std::fs::remove_file(&wat)),
4044
}
4145
}
4246

crates/fuzzing/src/oracles/dummy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use wasmtime::*;
66
/// Create a set of dummy functions/globals/etc for the given imports.
77
pub fn dummy_linker<'module>(store: &Store, module: &Module) -> Linker {
88
let mut linker = Linker::new(store);
9+
linker.allow_shadowing(true);
910
for import in module.imports() {
1011
match import.name() {
1112
Some(name) => {

0 commit comments

Comments
 (0)