Throw out fewer fuzz inputs with differential fuzzer (#4859)

* Throw out fewer fuzz inputs with differential fuzzer

Prior to this commit the differential fuzzer would generate a module and
then select an engine to execute the module against Wasmtime. This
meant, however, that the candidate list of engines were filtered against
the configuration used to generate the module to ensure that the
selected engine could run the generated module.

This commit inverts this logic and instead selects an engine first,
allowing the engine to then tweak the module configuration to ensure
that the generated module is compatible with the engine selected. This
means that fewer fuzz inputs are discarded because every fuzz input will
result in an engine being executed.

Internally the engine constructors have all been updated to update the
configuration to work instead of filtering the configuration. Some other
fixes were applied for the spec interpreter as well to work around #4852

* Fix tests
This commit is contained in:
Alex Crichton
2022-09-06 12:41:23 -05:00
committed by GitHub
parent 9856664f1f
commit 543a487939
8 changed files with 142 additions and 182 deletions

View File

@@ -38,11 +38,11 @@ impl Config {
// Make it more likely that there are types available to generate a
// function with.
config.min_types = 1;
config.min_types = config.min_types.max(1);
config.max_types = config.max_types.max(1);
// Generate at least one function
config.min_funcs = 1;
config.min_funcs = config.min_funcs.max(1);
config.max_funcs = config.max_funcs.max(1);
// Allow a memory to be generated, but don't let it get too large.
@@ -102,7 +102,7 @@ impl Config {
/// to ensure termination; as doing so will add an additional global to the module,
/// the pooling allocator, if configured, will also have its globals limit updated.
pub fn generate(
&mut self,
&self,
input: &mut Unstructured<'_>,
default_fuel: Option<u32>,
) -> arbitrary::Result<wasm_smith::Module> {

View File

@@ -24,17 +24,7 @@ pub struct SingleInstModule<'a> {
impl<'a> SingleInstModule<'a> {
/// Choose a single-instruction module that matches `config`.
pub fn new(u: &mut Unstructured<'a>, config: &mut ModuleConfig) -> arbitrary::Result<&'a Self> {
// To avoid skipping modules unnecessarily during fuzzing, fix up the
// `ModuleConfig` to match the inherent limits of a single-instruction
// module.
config.config.min_funcs = 1;
config.config.max_funcs = 1;
config.config.min_tables = 0;
config.config.max_tables = 0;
config.config.min_memories = 0;
config.config.max_memories = 0;
pub fn new(u: &mut Unstructured<'a>, config: &ModuleConfig) -> arbitrary::Result<&'a Self> {
// Only select instructions that match the `ModuleConfig`.
let instructions = &INSTRUCTIONS
.iter()