Skip to content

Commit 26e0629

Browse files
authored
Merge pull request bytecodealliance#1726 from fitzgen/fix-simple-automata-timeout
Limit the size of automaton keys in the `peepmatic_simple_automata` fuzz target
2 parents d8d6fbe + 9d2100e commit 26e0629

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

cranelift/peepmatic/crates/fuzzing/src/automata.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ where
1717
bincode::deserialize(&encoded).expect("should deserialize OK")
1818
}
1919

20+
const MAX_AUTOMATON_KEY_LEN: usize = 256;
21+
2022
/// Construct an automaton from the the given input-output pairs, and assert
2123
/// that:
2224
///
@@ -41,11 +43,19 @@ pub fn simple_automata(input_output_pairs: Vec<Vec<(u8, Vec<u8>)>>) {
4143
let mut input_output_pairs: Vec<_> = input_output_pairs
4244
.into_iter()
4345
.filter(|pair| {
44-
!pair.is_empty() && {
45-
// Make sure we don't have duplicate inputs.
46-
let is_new = inputs.insert(full_input(pair));
47-
is_new
46+
if pair.is_empty() {
47+
return false;
48+
}
49+
50+
// Make sure that we don't generate huge input keys.
51+
let full_input = full_input(pair);
52+
if full_input.len() >= MAX_AUTOMATON_KEY_LEN {
53+
return false;
4854
}
55+
56+
// Make sure we don't have duplicate inputs.
57+
let is_new = inputs.insert(full_input);
58+
is_new
4959
})
5060
.collect();
5161

@@ -111,7 +121,7 @@ pub fn fst_differential(map: HashMap<Vec<u8>, u64>) {
111121

112122
let mut inputs: Vec<_> = map
113123
.keys()
114-
.filter(|k| !k.is_empty() && k.len() < 256)
124+
.filter(|k| !k.is_empty() && k.len() < MAX_AUTOMATON_KEY_LEN)
115125
.cloned()
116126
.collect();
117127
inputs.sort();

0 commit comments

Comments
 (0)