Skip to content

Commit

Permalink
fuzz: set a size limit
Browse files Browse the repository at this point in the history
Otherwise it's possible for the fuzzer to build a regex that is big
enough to timeout on a big haystack.
  • Loading branch information
BurntSushi committed May 18, 2023
1 parent 98be16a commit a3978b2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fuzz/fuzz_targets/fuzz_regex_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ fuzz_target!(|data: &[u8]| {
let char_index = data.char_indices().nth(split_off_point);
if let Some((char_index, _)) = char_index {
let (pattern, input) = data.split_at(char_index);
if let Ok(re) = regex::Regex::new(pattern) {
let result =
regex::RegexBuilder::new(pattern).size_limit(1 << 20).build();
if let Ok(re) = result {
re.is_match(input);
}
}
Expand Down

0 comments on commit a3978b2

Please sign in to comment.