File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,3 +35,10 @@ path = "fuzzers/parse_date.rs"
3535test = false
3636doc = false
3737bench = false
38+
39+ [[bin ]]
40+ name = " parse_duration"
41+ path = " fuzzers/parse_duration.rs"
42+ test = false
43+ doc = false
44+ bench = false
Original file line number Diff line number Diff line change 1+ #![ no_main]
2+
3+ use libfuzzer_sys:: fuzz_target;
4+
5+ fuzz_target ! ( |data: & [ u8 ] | test_parse_duration( data) ) ;
6+
7+ pub fn test_parse_duration ( data : & [ u8 ] ) {
8+ use std:: str:: from_utf8;
9+ use std:: str:: FromStr ;
10+
11+ // input must be text
12+ let Ok ( original_text) = from_utf8 ( data) else {
13+ return ;
14+ } ;
15+
16+ // parse input as a duration
17+ let Ok ( duration) = prost_types:: Duration :: from_str ( original_text) else {
18+ if original_text. ends_with ( "s" ) {
19+ assert ! (
20+ original_text. parse:: <f64 >( ) . is_err( ) ,
21+ "prost failed to parse duration, but it seems to be a valid number: {}" ,
22+ original_text
23+ ) ;
24+ }
25+ return ;
26+ } ;
27+
28+ // roundtrip to and from string
29+ let roundtrip_text = format ! ( "{duration}" ) ;
30+ assert_eq ! ( Ok ( & duration) , roundtrip_text. parse( ) . as_ref( ) ) ;
31+ }
You can’t perform that action at this time.
0 commit comments