From 2696462ccbeaa4350200842b46d2c83da9aa4e19 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Aug 2022 10:56:27 -0500 Subject: [PATCH] Limit the size of functions in the `stacks` fuzzer (#4727) * Limit the size of functions in the `stacks` fuzzer The fuzzers recently found a timeout in this fuzz test case related to the compile time of the generated module. Inspecting the generated module showed that it had 100k+ opcodes for one function, so this commit updates the fuzzer to limit the number of operations per-function to a smaller amount to avoid timeout limits. * Use `arbitrary_len` for `ops` length * Fix a max/min flip --- crates/fuzzing/src/generators/stacks.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/fuzzing/src/generators/stacks.rs b/crates/fuzzing/src/generators/stacks.rs index ffb95158e3..8b5544d003 100644 --- a/crates/fuzzing/src/generators/stacks.rs +++ b/crates/fuzzing/src/generators/stacks.rs @@ -11,6 +11,7 @@ use arbitrary::{Arbitrary, Result, Unstructured}; use wasm_encoder::Instruction; const MAX_FUNCS: usize = 20; +const MAX_OPS: usize = 1_000; /// Generate a Wasm module that keeps track of its current call stack, to /// compare to the host. @@ -50,7 +51,10 @@ impl Stacks { let mut work_list = vec![0]; while let Some(f) = work_list.pop() { - let mut ops = u.arbitrary::>()?; + let mut ops = Vec::with_capacity(u.arbitrary_len::()?.min(MAX_OPS)); + for _ in 0..ops.capacity() { + ops.push(u.arbitrary()?); + } for op in &mut ops { match op { Op::CallThroughHost(idx) | Op::Call(idx) => {