Skip to content

Avoid bounded backtracker when max haystack length is zero - #1384

Open
fyrsta7 wants to merge 1 commit into
rust-lang:masterfrom
fyrsta7:fix/bounded-backtracker-zero-max
Open

Avoid bounded backtracker when max haystack length is zero#1384
fyrsta7 wants to merge 1 commit into
rust-lang:masterfrom
fyrsta7:fix/bounded-backtracker-zero-max

Conversation

@fyrsta7

@fyrsta7 fyrsta7 commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Fixes #1344 by avoiding the bounded backtracker in the meta engine when its computed maximum haystack length is zero.

Details

The meta wrapper already skips the bounded backtracker when the input span is longer than max_haystack_len(). When the maximum saturates to zero, an empty input span is not greater than the maximum, so the wrapper still selected the backtracker. The backtracker then returned HaystackTooLong { len: 0 }, which the wrapper unwrapped.

This treats a zero maximum as meaning the backtracker should not be used for that regex and lets the meta engine fall through to the next strategy.

Validation

  • git diff --check
  • cargo fmt --all --check
  • cargo test -p regex-automata backtracker_zero_max_haystack_len --test integration --features meta -- --nocapture
  • cargo test -p regex-automata --features meta,nfa-backtrack

@fyrsta7
fyrsta7 marked this pull request as ready for review August 8, 2026 13:51
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.

BoundedBacktracker::is_match panics on empty haystack when max_haystack_len() saturates to 0

1 participant