Skip to content

Commit 39d8b45

Browse files
committed
automata: fix invalid accelerators
It's possible for DFA deserialization to result in an otherwise valid DFA, but one that records accelerated DFA states without any actual accelerator. We remedy that by checking for it at deserialization time. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60739 Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61255 fixup
1 parent 912479c commit 39d8b45

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

regex-automata/src/dfa/dense.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,24 @@ impl<'a> DFA<&'a [u32]> {
23462346
dfa.accels.validate()?;
23472347
// N.B. dfa.special doesn't have a way to do unchecked deserialization,
23482348
// so it has already been validated.
2349+
for state in dfa.states() {
2350+
// If the state is an accel state, then it must have a non-empty
2351+
// accelerator.
2352+
if dfa.is_accel_state(state.id()) {
2353+
let index = dfa.accelerator_index(state.id());
2354+
if index >= dfa.accels.len() {
2355+
return Err(DeserializeError::generic(
2356+
"found DFA state with invalid accelerator index",
2357+
));
2358+
}
2359+
let needles = dfa.accels.needles(index);
2360+
if !(1 <= needles.len() && needles.len() <= 3) {
2361+
return Err(DeserializeError::generic(
2362+
"accelerator needles has invalid length",
2363+
));
2364+
}
2365+
}
2366+
}
23492367
Ok((dfa, nread))
23502368
}
23512369

0 commit comments

Comments
 (0)