File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
cranelift/peepmatic/crates/fuzzing/src Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 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 ( ) ;
You can’t perform that action at this time.
0 commit comments