Skip to content

meta::Cache::reset can panic #1155

Description

@fuchsnj

What version of regex are you using?

Latest / 0.4.4

Describe the bug at a high level.

Calling .reset(..) on a meta::Cache can panic if called on a different regex than it was created with (which is the whole point of reset).

What are the steps to reproduce the behavior?

use regex_automata::meta::Regex;

fn main() {
    let re1 = Regex::new("").unwrap();
    let re2 = Regex::new("\\b").unwrap();
    re1.create_cache().reset(&re2);
}

What is the actual behavior?

thread 'main' panicked at /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-automata-0.4.3/src/meta/wrappers.rs:507:29:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:127:5
   3: core::option::Option<T>::unwrap
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:931:21
   4: regex_automata::meta::wrappers::OnePassCache::reset
             at ./.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-automata-0.4.3/src/meta/wrappers.rs:507:13
   5: <regex_automata::meta::strategy::Core as regex_automata::meta::strategy::Strategy>::reset_cache
             at ./.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-automata-0.4.3/src/meta/strategy.rs:688:9
   6: regex_automata::meta::regex::Cache::reset
             at ./.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-automata-0.4.3/src/meta/regex.rs:2385:9
   7: playground::main
             at ./src/main.rs:6:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

What is the expected behavior?

It should not panic, and allow using that cache on the new regex.

Additional info

One example of a location this panics is: https://github.com/rust-lang/regex/blob/master/regex-automata/src/meta/wrappers.rs#L799
although it looks like other reset implementations have similar issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions