pomsky icon indicating copy to clipboard operation
pomsky copied to clipboard

Detect catastrophic backtracking

Open Aloso opened this issue 2 years ago • 0 comments

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 avatar Oct 30 '23 12:10 Aloso