-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge all fuzz targets into one (#1193)
* Merge all fuzz targets into one This commit merges all fuzz targets in this repository into one fuzz target. The goal here is to have better control over how these fuzz targets run on oss-fuzz. I've discovered recently that of the 22 fuzz targets that the Wasmtime project has less than 10 are running each day meaning that the coverage can be spotty throughout the time that fuzzers are running. This appears to be due to the fact that the time slicing unit is for individual fuzzers and presumably Wasmtime reached its quota for the day running those fuzzers. By merging all fuzzers into one binary the hope is that we're able to have more fine-grained control over what's fuzzed when rather than being at the mercy of oss-fuzz. This commit replaces 9 fuzzers with 1 single fuzzer. The new fuzzer is structured generally as taking the first byte as a discriminant of which sub-fuzzer to run. For string-taking fuzzers I figured it'd be convenient if the input was literally a string still so the string-based fuzzers will all run on valid utf-8 inputs. * Run rustfmt * Fix wasmtime build
- Loading branch information
1 parent
e2af293
commit e29e4ca
Showing
15 changed files
with
187 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#![no_main] | ||
|
||
use arbitrary::Unstructured; | ||
use libfuzzer_sys::fuzz_target; | ||
use std::sync::OnceLock; | ||
|
||
// Helper macro which takes a static list of fuzzers as input which are then | ||
// delegated to internally based on the fuzz target selected. | ||
// | ||
// In general this fuzz target will execute a number of fuzzers all with the | ||
// same input. The `FUZZER` environment variable can be used to forcibly disable | ||
// all but one. | ||
macro_rules! run_fuzzers { | ||
($($fuzzer:ident: $kind:ident,)*) => { | ||
static ENABLED: OnceLock<u32> = OnceLock::new(); | ||
|
||
fuzz_target!(|bytes: &[u8]| { | ||
// Lazily initialize this fuzzer in terms of logging as well as | ||
// enabled fuzzers via the `FUZZER` env var. | ||
let enabled = *ENABLED.get_or_init(|| { | ||
env_logger::init(); | ||
let configured = std::env::var("FUZZER").ok(); | ||
let configured = configured.as_deref(); | ||
let mut enabled = 0; | ||
let mut index = 0; | ||
|
||
$( | ||
if configured.is_none() || configured == Some(stringify!($fuzzer)) { | ||
enabled |= 1 << index; | ||
} | ||
index += 1; | ||
)* | ||
let _ = index; | ||
|
||
enabled | ||
}); | ||
|
||
let mut index = 0; | ||
$( | ||
if enabled & (1 << index) != 0 { | ||
run_fuzzers!(@run $fuzzer $kind bytes index); | ||
} | ||
index += 1; | ||
)* | ||
let _ = index; | ||
}); | ||
}; | ||
|
||
(@run $fuzzer:ident unstructured $bytes:ident $index:ident) => { | ||
// Use the first byte of input as a discriminant of which fuzzer to | ||
// select. | ||
// | ||
// Afterwards run the specific fuzzer that the fuzz input is | ||
// targeted for so long as it's enabled. | ||
if let Some((which_fuzzer, bytes)) = $bytes.split_first() { | ||
if *which_fuzzer == $index { | ||
let mut u = Unstructured::new(bytes); | ||
let _ = wasm_tools_fuzz::$fuzzer::run(&mut u); | ||
} | ||
} | ||
}; | ||
|
||
(@run $fuzzer:ident string $bytes:ident $index:ident) => { | ||
// For string-based fuzzers run all fuzzers enabled for all | ||
// string-looking inputs. | ||
if let Ok(s) = std::str::from_utf8($bytes) { | ||
wasm_tools_fuzz::$fuzzer::run(s); | ||
} | ||
}; | ||
} | ||
|
||
run_fuzzers! { | ||
mutate: unstructured, | ||
validate_valid_module: unstructured, | ||
roundtrip_wit: unstructured, | ||
no_traps: unstructured, | ||
validate: unstructured, | ||
incremental_parse: unstructured, | ||
print: unstructured, | ||
roundtrip: string, | ||
text_parser: string, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use arbitrary::{Result, Unstructured}; | ||
|
||
pub fn run(u: &mut Unstructured<'_>) -> Result<()> { | ||
let data = u.bytes(u.len())?; | ||
drop(wasmprinter::print_bytes(data)); | ||
Ok(()) | ||
} |
Oops, something went wrong.