Skip to content

Commit 09b55df

Browse files
committed
automata: fix validation order in dense::DFA::from_bytes
1 parent eab5b61 commit 09b55df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

regex-automata/src/dfa/dense.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,10 +2340,14 @@ impl<'a> DFA<&'a [u32]> {
23402340
// table, match states and accelerators below. If any validation fails,
23412341
// then we return an error.
23422342
let (dfa, nread) = unsafe { DFA::from_bytes_unchecked(slice)? };
2343+
// Note: Validation order is important here:
2344+
// - MatchState::validate can be called with an untrusted DFA.
2345+
// - TransistionTable::validate uses dfa.ms through match_len
2346+
// - StartTable::validate needs a valid transition table
2347+
dfa.accels.validate()?;
2348+
dfa.ms.validate(&dfa)?;
23432349
dfa.tt.validate(&dfa)?;
23442350
dfa.st.validate(&dfa)?;
2345-
dfa.ms.validate(&dfa)?;
2346-
dfa.accels.validate()?;
23472351
// N.B. dfa.special doesn't have a way to do unchecked deserialization,
23482352
// so it has already been validated.
23492353
for state in dfa.states() {

0 commit comments

Comments
 (0)