Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta::Cache::reset can panic #1155

Open
fuchsnj opened this issue Jan 24, 2024 · 0 comments
Open

meta::Cache::reset can panic #1155

fuchsnj opened this issue Jan 24, 2024 · 0 comments
Labels

Comments

@fuchsnj
Copy link

fuchsnj commented Jan 24, 2024

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.

@BurntSushi BurntSushi added the bug label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants