Skip to content

Detect catastrophic backtracking #99

@Aloso

Description

@Aloso

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-diagnosticsWarnings and errors reported by PomskyenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions