1- #![ no_main]
2-
3- use arbitrary:: Arbitrary ;
4- use libfuzzer_sys:: { fuzz_target, Corpus } ;
5-
6- use simplicityhl:: { ArbitraryOfType , Arguments } ;
1+ #![ cfg_attr( fuzzing, no_main) ]
72
83/// The PEST parser is slow for inputs with many open brackets.
94/// Detect some of these inputs to reject them from the corpus.
105///
116/// ```text
127/// fn n(){ { (s,(( (Ns,(s,(x,(((s,((s,(s,(s,(x,(( {5
138/// ```
9+ #[ cfg( any( fuzzing, test) ) ]
1410fn slow_input ( program_text : & str ) -> bool {
1511 let mut consecutive_open_brackets = 0 ;
1612
@@ -28,7 +24,12 @@ fn slow_input(program_text: &str) -> bool {
2824 false
2925}
3026
31- fuzz_target ! ( |data: & [ u8 ] | -> Corpus {
27+ #[ cfg( any( fuzzing, test) ) ]
28+ fn do_test ( data : & [ u8 ] ) -> libfuzzer_sys:: Corpus {
29+ use arbitrary:: Arbitrary ;
30+ use libfuzzer_sys:: Corpus ;
31+ use simplicityhl:: { ArbitraryOfType , Arguments } ;
32+
3233 let mut u = arbitrary:: Unstructured :: new ( data) ;
3334
3435 let program_text = match <String >:: arbitrary ( & mut u) {
@@ -49,4 +50,25 @@ fuzz_target!(|data: &[u8]| -> Corpus {
4950 let _ = template. instantiate ( arguments, false ) ;
5051
5152 Corpus :: Keep
53+ }
54+
55+ #[ cfg( fuzzing) ]
56+ libfuzzer_sys:: fuzz_target!( |data: & [ u8 ] | {
57+ let _ = do_test( data) ;
5258} ) ;
59+
60+ #[ cfg( not( fuzzing) ) ]
61+ fn main ( ) { }
62+
63+ #[ cfg( test) ]
64+ mod tests {
65+ use base64:: Engine ;
66+
67+ #[ test]
68+ fn duplicate_crash ( ) {
69+ let data = base64:: prelude:: BASE64_STANDARD
70+ . decode ( "Cg==" )
71+ . expect ( "base64 should be valid" ) ;
72+ super :: do_test ( & data) ;
73+ }
74+ }
0 commit comments