Skip to content

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

Description

@Stranger6667

What version of regex are you using?

regex-automata 0.4.14

Describe the bug at a high level.

Panic in BoundedBacktracker::is_match while I'd expect an Err during regex construction time (despite the large size limit). Appeared in the jsonschema crate when I tried to compile all regular expressions I mined from the Open API directory repo.

What are the steps to reproduce the behavior?

use regex_automata::meta::Regex;

let cfg = Regex::config().nfa_size_limit(Some(1_000_000_000));
let re = Regex::builder().configure(cfg).build(r"^.{0,404600}$").unwrap();
re.is_match("");  // panics

What is the actual behavior?

Panic:

thread 'main' panicked at regex-automata-0.4.14/src/meta/wrappers.rs:234:68:
called `Result::unwrap()` on an `Err` value: MatchError(HaystackTooLong { len: 0 })

What is the expected behavior?

I'd expect either a build-time error (like the existing CompiledTooBig for this shape, see #802) or a clean runtime Err - but not a panic:

Regex::builder().configure(cfg).build(r"^.{0,404600}$")

Additionally, HaystackTooLong with len: 0 reads weird as I'd expect some large value there instead of 0 (implied by the TooLong part of the enum variant name).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions