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

Detect catastrophic backtracking #99

Open
Aloso opened this issue Oct 30, 2023 · 0 comments
Open

Detect catastrophic backtracking #99

Aloso opened this issue Oct 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Aloso
Copy link
Member

Aloso commented Oct 30, 2023

Is your feature request related to a problem? Please describe.

Most regex engines supported by Pomsky use backtracking. This means that Pomsky is susceptible to catastrophic backtracking. This should be detected and issue a warning (unless Rust is targeted, which does not backtrack).

Describe the solution you'd like

The regular-expressions.info page about catastrophic backtracking recommends:

The solution is simple. When nesting repetition operators, make absolutely sure that there is only one way to match the same match.

But is this sufficient? A real-word example where backtracking crippled a CloudFlare service was the regex

(?:\"|'|\]|\}|\\|\d|nan|infinity|true|false|null|undefined|symbol|math|\`|\-|\+)+[)]*;?(?:\s|-|~|!|{}|\|\||\+)*.*(?:.*=.*)

Which can be simplified and summarized like this:

something* .* .* '=' .*

There is no nested repetition, yet it is susceptible to catastrophic backtracking.

@Aloso Aloso added the enhancement New feature or request label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant