automata: don't use the backtracker when it can't search any haystack#1376
Open
kimjune01 wants to merge 1 commit into
Open
automata: don't use the backtracker when it can't search any haystack#1376kimjune01 wants to merge 1 commit into
kimjune01 wants to merge 1 commit into
Conversation
The bounded backtracker needs `len(NFA states) * (len(haystack) + 1)` bits of visited capacity. When the NFA is big enough relative to that capacity, it cannot search even an empty haystack. `BoundedBacktracker::max_haystack_len` saturates to `0` in that case, which is indistinguishable from "an empty haystack is fine." The meta engine's length check is `len > max_haystack_len()`, so an empty haystack passed it, the search returned `HaystackTooLong`, and `BoundedBacktrackerEngine::is_match` unwrapped that error and panicked. The meta engine now declines to build the backtracker at all when it lacks the capacity for a zero-length haystack, which restores the invariant that this engine is only reachable for haystacks it can actually search. Note that only the empty haystack panicked. For any longer haystack the existing length check already rejected the backtracker. Fixes rust-lang#1344
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I picked this up with a failing on main, pass on branch. It seems that the haystack length being expressed by 0 can sometimes be overloaded with what it means. I added a case to disambiguate.
The new test panics on master and passes here.
cargo test -p regex-automataand-p regexare green,cargo fmt --checkis clean.Fixes #1344