Skip to content

Commit d15645b

Browse files
committed
fuzzgen: Limit the amount of test case inputs
1 parent 3d810c6 commit d15645b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cranelift/fuzzgen/src/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use std::ops::RangeInclusive;
33

44
/// Holds the range of acceptable values to use during the generation of testcases
55
pub struct Config {
6-
pub test_case_inputs: RangeInclusive<usize>,
6+
/// Maximum allowed test case inputs.
7+
/// We build test case inputs from the rest of the bytes that the fuzzer provides us
8+
/// so we allow the fuzzer to control this by feeding us more or less bytes.
9+
/// The upper bound here is to prevent too many inputs that cause long test times
10+
pub max_test_case_inputs: usize,
711
pub signature_params: RangeInclusive<usize>,
812
pub signature_rets: RangeInclusive<usize>,
913
pub instructions_per_block: RangeInclusive<usize>,
@@ -65,7 +69,7 @@ pub struct Config {
6569
impl Default for Config {
6670
fn default() -> Self {
6771
Config {
68-
test_case_inputs: 1..=10,
72+
max_test_case_inputs: 100,
6973
signature_params: 0..=16,
7074
signature_rets: 0..=16,
7175
instructions_per_block: 0..=64,

cranelift/fuzzgen/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ where
149149
fn generate_test_inputs(mut self, signature: &Signature) -> Result<Vec<TestCaseInput>> {
150150
let mut inputs = Vec::new();
151151

152-
loop {
152+
// Generate up to "max_test_case_inputs" inputs, we need an upper bound here since
153+
// the fuzzer at some point starts trying to feed us way too many inputs. (I found one
154+
// test case with 130k inputs!)
155+
for _ in 0..self.config.max_test_case_inputs {
153156
let last_len = self.u.len();
154157

155158
let test_args = signature

0 commit comments

Comments
 (0)