mirror of
https://gitee.com/openharmony/third_party_rust_regex
synced 2025-04-07 04:32:01 +00:00

This improves the precision of the "expression too big" regex compilation error. Previously, it was not considering the heap usage from Unicode character classes. It's possible this will make some regexes fail to compile that previously compiled. However, this is a bug fix. If you do wind up seeing this though, feel free to file an issue, since it would be good to get an idea of what kinds of regexes no longer compile but did. This was found by OSS-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33579
32 lines
1.1 KiB
Rust
32 lines
1.1 KiB
Rust
// These tests are only run for the "default" test target because some of them
|
|
// can take quite a long time. Some of them take long enough that it's not
|
|
// practical to run them in debug mode. :-/
|
|
|
|
// See: https://oss-fuzz.com/testcase-detail/5673225499181056
|
|
//
|
|
// Ignored by default since it takes too long in debug mode (almost a minute).
|
|
#[test]
|
|
#[ignore]
|
|
fn fuzz1() {
|
|
regex!(r"1}{55}{0}*{1}{55}{55}{5}*{1}{55}+{56}|;**");
|
|
}
|
|
|
|
// See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26505
|
|
// See: https://github.com/rust-lang/regex/issues/722
|
|
#[test]
|
|
fn empty_any_errors_no_panic() {
|
|
assert!(regex_new!(r"\P{any}").is_err());
|
|
}
|
|
|
|
// This tests that a very large regex errors during compilation instead of
|
|
// using gratuitous amounts of memory. The specific problem is that the
|
|
// compiler wasn't accounting for the memory used by Unicode character classes
|
|
// correctly.
|
|
//
|
|
// See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33579
|
|
#[test]
|
|
fn big_regex_fails_to_compile() {
|
|
let pat = "[\u{0}\u{e}\u{2}\\w~~>[l\t\u{0}]p?<]{971158}";
|
|
assert!(regex_new!(pat).is_err());
|
|
}
|