Skip to content

automata: reject sparse DFA pattern IDs that are out of range - #1427

Open
safa-rk wants to merge 1 commit into
rust-lang:masterfrom
safa-rk:sparse-pattern-id-range
Open

safa-rk wants to merge 1 commit into
rust-lang:masterfrom
safa-rk:sparse-pattern-id-range

Conversation

@safa-rk

@safa-rk safa-rk commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

a serialized sparse DFA can carry a match state whose pattern IDs are not below the pattern length it records. Transitions::try_state only checks each pattern ID against PatternID::LIMIT, so sparse::DFA::from_bytes accepts it, while the dense MatchStates::validate rejects the same thing. a search with such a DFA then reports a HalfMatch whose pattern() is out of range for pattern_len(): with three patterns and the pattern length rewritten to 2, try_search_fwd on "c" reports pattern 2 and try_which_overlapping_matches panics in PatternSet::insert with a set sized by pattern_len(). this adds the range check to try_state, the one place sparse states are decoded during validation, and a regression test next to the existing ones.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant