Skip to content

zero repetition capture groups and search slots panic #1327

@keith-hall

Description

@keith-hall

Hi,

I have observed a reliable way to cause a panic, when using search_slots on a regex_automata::meta::regex which was built from a pattern containing a capture group which has zero repetition. i.e. (abc){0}

It panics if the Vec passed in has space for the capture group - which will never be populated because it is inside a zero repetition.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=36195dbc5f4283f3400ec084c1ec2fd2

It seems like in general, regex-automata doesn't mind when the Vec has room for more slots than is required - except when the pattern contains this zero-repetition capture group... As can be seen in the Rust Playground link above, it panics...

I know there may seem to be no real use case for supporting patterns with capture groups which essentially are ignored, but there is a reason for the madness, described a little at #1326

thread 'main' (40) panicked at /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/regex-automata-0.4.13/src/dfa/onepass.rs:2576:33:
range end index 4 out of range for slice of length 2

It is legal to pass any number of slots to this routine. If the regex engine would otherwise write a slot offset that doesn’t fit in the provided slice, then it is simply skipped.

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