/src/regex/fuzz/fuzz_targets/fuzz_regex_match.rs
Line | Count | Source (jump to first uncovered line) |
1 | | #![no_main] |
2 | | |
3 | | use libfuzzer_sys::{arbitrary, fuzz_target, Corpus}; |
4 | | |
5 | 46.7k | #[derive(arbitrary::Arbitrary)] Unexecuted instantiation: <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary::{closure#0} Unexecuted instantiation: <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary::{closure#1} Unexecuted instantiation: <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary::{closure#2} Unexecuted instantiation: <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0} Unexecuted instantiation: <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#2} <fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#1} Line | Count | Source | 5 | 23.3k | #[derive(arbitrary::Arbitrary)] |
<fuzz_regex_match::FuzzCase as arbitrary::Arbitrary>::try_size_hint::{closure#0} Line | Count | Source | 5 | 23.3k | #[derive(arbitrary::Arbitrary)] |
|
6 | | struct FuzzCase<'a> { |
7 | | pattern: &'a str, |
8 | | haystack: &'a str, |
9 | | case_insensitive: bool, |
10 | | multi_line: bool, |
11 | | dot_matches_new_line: bool, |
12 | | swap_greed: bool, |
13 | | ignore_whitespace: bool, |
14 | | unicode: bool, |
15 | | octal: bool, |
16 | | } |
17 | | |
18 | | impl std::fmt::Debug for FuzzCase<'_> { |
19 | 0 | fn fmt( |
20 | 0 | &self, |
21 | 0 | fmt: &mut std::fmt::Formatter, |
22 | 0 | ) -> Result<(), std::fmt::Error> { |
23 | 0 | let FuzzCase { |
24 | 0 | pattern, |
25 | 0 | case_insensitive, |
26 | 0 | multi_line, |
27 | 0 | dot_matches_new_line, |
28 | 0 | swap_greed, |
29 | 0 | ignore_whitespace, |
30 | 0 | unicode, |
31 | 0 | octal, |
32 | 0 | haystack, |
33 | 0 | } = self; |
34 | 0 |
|
35 | 0 | write!( |
36 | 0 | fmt, |
37 | 0 | r#" |
38 | 0 | let Ok(re) = regex::RegexBuilder::new({pattern:?}) |
39 | 0 | .case_insensitive({case_insensitive:?}) |
40 | 0 | .multi_line({multi_line:?}) |
41 | 0 | .dot_matches_new_line({dot_matches_new_line:?}) |
42 | 0 | .swap_greed({swap_greed:?}) |
43 | 0 | .ignore_whitespace({ignore_whitespace:?}) |
44 | 0 | .unicode({unicode:?}) |
45 | 0 | .octal({octal:?}) |
46 | 0 | .size_limit(1<<20) |
47 | 0 | .build() else {{ return }}; |
48 | 0 | re.is_match({haystack:?}); |
49 | 0 | "# |
50 | 0 | ) |
51 | 0 | } |
52 | | } |
53 | | |
54 | | fuzz_target!(|case: FuzzCase| -> Corpus { |
55 | | let _ = env_logger::try_init(); |
56 | | |
57 | | if case.pattern.len() > (16 * (1 << 10)) { |
58 | | return Corpus::Reject; |
59 | | } |
60 | | if case.haystack.len() > (16 * (1 << 10)) { |
61 | | return Corpus::Reject; |
62 | | } |
63 | | let Ok(re) = regex::RegexBuilder::new(case.pattern) |
64 | | .case_insensitive(case.case_insensitive) |
65 | | .multi_line(case.multi_line) |
66 | | .dot_matches_new_line(case.dot_matches_new_line) |
67 | | .swap_greed(case.swap_greed) |
68 | | .ignore_whitespace(case.ignore_whitespace) |
69 | | .unicode(case.unicode) |
70 | | .octal(case.octal) |
71 | | .size_limit(1 << 18) |
72 | | .build() |
73 | | else { |
74 | | return Corpus::Reject; |
75 | | }; |
76 | | re.is_match(case.haystack); |
77 | | Corpus::Keep |
78 | | }); |