File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,9 @@ name = "fuzz_file_section"
32
32
path = " fuzz_targets/fuzz_file_section.rs"
33
33
test = false
34
34
doc = false
35
+
36
+ [[bin ]]
37
+ name = " fuzz_file"
38
+ path = " fuzz_targets/fuzz_file.rs"
39
+ test = false
40
+ doc = false
Original file line number Diff line number Diff line change
1
+ #![ no_main]
2
+
3
+ use arbitrary:: Arbitrary ;
4
+ use gix_config:: {
5
+ file:: { init:: Options , Metadata } ,
6
+ File ,
7
+ } ;
8
+ use libfuzzer_sys:: fuzz_target;
9
+ use std:: hint:: black_box;
10
+
11
+ #[ derive( Arbitrary , Debug ) ]
12
+ struct Ctx < ' a > {
13
+ input : & ' a [ u8 ] ,
14
+ sections_by_name : & ' a str ,
15
+ }
16
+
17
+ macro_rules! unwrap_or_return {
18
+ ( $e: expr) => {
19
+ match $e {
20
+ Ok ( val) => val,
21
+ Err ( _) => return ,
22
+ }
23
+ } ;
24
+ }
25
+
26
+ fuzz_target ! ( |ctx: Ctx | {
27
+ let meta = Metadata :: default ( ) ;
28
+ let options = Options :: default ( ) ;
29
+ let file = unwrap_or_return!( File :: from_bytes_no_includes( & ctx. input, meta. clone( ) , options. clone( ) ) ) ;
30
+ _ = black_box( file. sections( ) . count( ) ) ;
31
+ _ = black_box( file. sections_and_ids( ) . count( ) ) ;
32
+ _ = black_box( file. sections_and_postmatter( ) . count( ) ) ;
33
+ _ = black_box( file. sections_by_name( ctx. sections_by_name) . map( |x| x. count( ) ) ) ;
34
+ _ = black_box( file. frontmatter( ) ) ;
35
+
36
+ let roundtrip_as_string: Vec <u8 > = file. to_bstring( ) . into( ) ;
37
+ _ = unwrap_or_return!( black_box( File :: from_bytes_no_includes(
38
+ & roundtrip_as_string,
39
+ meta. clone( ) ,
40
+ options. clone( ) ,
41
+ ) ) ) ;
42
+ } ) ;
You can’t perform that action at this time.
0 commit comments