Repository navigation
Conversation
Issue rust-lang#1344: When a regex like /^.{0,404600}$/ causes the bounded backtracker's max_haystack_len() to return 0, the meta layer's guard in wrappers.rs used '>' instead of '>=', allowing the engine to be selected for an empty string (length 0). The engine then panicked with MatchError(HaystackTooLong { len: 0 }) from an unwrap(). The fix changes the guard from '>' to '>=' so that when max_haystack_len() is 0, no haystack (including the empty string) is excluded from the backtracker engine. Added regression test max_haystack_len_zero_excludes_engine.
VrtxOmega
force-pushed
the
fix/meta-backtracker-zero-haystack
branch
from
August 21, 2026 15:09
5de4b19 to
e926ddc
Compare
This branch has not been deployed
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.
Fixes #1344
Problem
When a regex like ^.{0,404600}$ causes the bounded backtracker's max_haystack_len() to return 0, the meta layer's guard in wrappers.rs used '>' instead of '>=', allowing the engine to be selected for an empty string (length 0). The engine then panicked with MatchError(HaystackTooLong { len: 0 }) from an unwrap() at wrappers.rs:234.
Root Cause
In src/meta/wrappers.rs, BoundedBacktrackerEngine::get() guards against haystacks that are too long for the backtracker:
When max_haystack_len() returns 0, this guard evaluates to (false), so the engine IS selected. But the engine itself cannot handle any haystack (even length 0) and returns an error.
Fix
Changed the guard from '>' to '>=' so that when max_haystack_len() is 0, no haystack is selected for the backtracker engine:
Verification