Skip to content

Oniguruma (used by uu expr) panics on backtracking regexes #11612

@sylvestre

Description

@sylvestre

This is an additional detail relevant to #1145 .

The following regex causes uu expr to panic:

root@03081849be59:/tmp# expr --version
expr (uutils coreutils) 0.6.0
root@03081849be59:/tmp# expr "$(perl -e "print \"a\"x25 . \"c\"")" : "\(a\+a\+\)\+b"

thread 'main' (1403) panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/onig-6.5.1/src/lib.rs:647:23:
Onig: Regex search error: retry-limit-in-match over
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted

Note that while GNU expr's regex engine supports backreferences, it does not appear to have exponential time complexity for this regex:

root@b082d601e194:/tmp# expr --version
expr (GNU coreutils) 9.7
Packaged by Debian (9.7-3)
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker, James Youngman, and Paul Eggert.
root@b082d601e194:/tmp# time expr "$(perl -e "print \"a\"x25 . \"c\"")" : "\(a\+a\+\)\+b"


real    0m0.018s
user    0m0.003s
sys     0m0.016s
root@b082d601e194:/tmp# time expr "$(perl -e "print \"a\"x100000 . \"c\"")" : "\(a\+a\+\)\+b"


real    0m0.021s
user    0m0.004s
sys     0m0.017s

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions