Skip to content

Commit c1dcf3e

Browse files
committed
utilise nfa size limits to prevent oom
1 parent b5c53cb commit c1dcf3e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fuzz/fuzz_targets/ast_diff_default.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use {
44
libfuzzer_sys::{fuzz_target, Corpus},
55
regex::RegexBuilder,
6-
regex_automata::nfa::thompson::pikevm::PikeVM as NfaRegex,
6+
regex_automata::nfa::thompson::{pikevm::PikeVM as NfaRegex, NFA},
77
regex_syntax::ast::Ast,
88
};
99

@@ -26,11 +26,15 @@ fuzz_target!(|data: FuzzData| -> Corpus {
2626
let _ = env_logger::try_init();
2727

2828
let pattern = format!("{}", data.ast);
29-
let Ok(re) = RegexBuilder::new(&pattern).size_limit(1<<20).build() else {
29+
let Ok(re) = RegexBuilder::new(&pattern).size_limit(1 << 20).build() else {
3030
return Corpus::Reject;
3131
};
32-
let Ok(baseline) = NfaRegex::new(&pattern) else {
33-
return Corpus::Reject; // should we error here?
32+
let config = NFA::config().nfa_size_limit(Some(1 << 20));
33+
let Ok(nfa) = NFA::compiler().configure(config).build(&pattern) else {
34+
return Corpus::Reject;
35+
};
36+
let Ok(baseline) = NfaRegex::new_from_nfa(nfa) else {
37+
return Corpus::Reject;
3438
};
3539
let mut cache = baseline.create_cache();
3640

0 commit comments

Comments
 (0)