File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ cargo-fuzz = true
12
12
[dependencies ]
13
13
libfuzzer-sys = " 0.4.7"
14
14
arbitrary = { version = " 1" , features = [" derive" ] }
15
+ bstr = " 1.8.0"
15
16
16
17
[dependencies .gix-config ]
17
18
path = " .."
@@ -25,3 +26,9 @@ name = "parse"
25
26
path = " fuzz_targets/parse.rs"
26
27
test = false
27
28
doc = false
29
+
30
+ [[bin ]]
31
+ name = " fuzz_file"
32
+ path = " fuzz_targets/fuzz_file.rs"
33
+ test = false
34
+ 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
+ for section in file. sections( ) {
37
+ for key in section. keys( ) {
38
+ _ = black_box(
39
+ section
40
+ . value_implicit( key. as_ref( ) )
41
+ . expect( "The key exists, so should the value." ) ,
42
+ ) ;
43
+ }
44
+ }
45
+
46
+ let roundtrip_as_string: Vec <u8 > = file. to_bstring( ) . into( ) ;
47
+ _ = unwrap_or_return!( black_box( File :: from_bytes_no_includes(
48
+ & roundtrip_as_string,
49
+ meta. clone( ) ,
50
+ options. clone( ) ,
51
+ ) ) ) ;
52
+ } ) ;
You can’t perform that action at this time.
0 commit comments