|
1 | 1 | #![no_main]
|
| 2 | + |
2 | 3 | use libfuzzer_sys::fuzz_target;
|
3 | 4 |
|
4 | 5 | fuzz_target!(|data: &[u8]| {
|
| 6 | + let _ = run(data); |
| 7 | +}); |
| 8 | + |
| 9 | +fn run(data: &[u8]) -> Option<()> { |
5 | 10 | if data.len() < 2 {
|
6 |
| - return; |
| 11 | + return None; |
7 | 12 | }
|
8 |
| - let split_point = data[0] as usize; |
9 |
| - if let Ok(data) = std::str::from_utf8(&data[1..]) { |
10 |
| - use std::cmp::max; |
11 |
| - // split data into regular expression and actual input to search through |
12 |
| - let len = data.chars().count(); |
13 |
| - let split_off_point = max(split_point, 1) % len as usize; |
14 |
| - let char_index = data.char_indices().nth(split_off_point); |
15 |
| - if let Some((char_index, _)) = char_index { |
16 |
| - let (pattern, input) = data.split_at(char_index); |
17 |
| - // If the haystack is big, don't use it. The issue is that |
18 |
| - // the fuzzer is compiled with sanitizer options and it makes |
19 |
| - // everything pretty slow. This was put in here as a result of |
20 |
| - // getting timeout errors from OSS-fuzz. There's really nothing to |
21 |
| - // be done about them. Unicode word boundaries in the PikeVM are |
22 |
| - // slow. It is what it is. |
23 |
| - if input.len() >= 8 * (1 << 10) { |
24 |
| - return; |
25 |
| - } |
26 |
| - let result = |
27 |
| - regex::RegexBuilder::new(pattern).size_limit(1 << 18).build(); |
28 |
| - if let Ok(re) = result { |
29 |
| - re.is_match(input); |
30 |
| - } |
31 |
| - } |
32 |
| - } |
33 |
| -}); |
| 13 | + let mut split_at = usize::from(data[0]); |
| 14 | + let data = std::str::from_utf8(&data[1..]).ok()?; |
| 15 | + // Split data into a regex and haystack to search. |
| 16 | + let len = usize::try_from(data.chars().count()).ok()?; |
| 17 | + split_at = std::cmp::max(split_at, 1) % len; |
| 18 | + let char_index = data.char_indices().nth(split_at)?.0; |
| 19 | + let (pattern, input) = data.split_at(char_index); |
| 20 | + let re = regex::Regex::new(pattern).ok()?; |
| 21 | + re.is_match(input); |
| 22 | + Some(()) |
| 23 | +} |
0 commit comments