Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Detect quadratic patterns #23

Closed
RunDevelopment opened this issue Oct 12, 2020 · 1 comment
Closed

Detect quadratic patterns #23

RunDevelopment opened this issue Oct 12, 2020 · 1 comment
Labels
new rule rule It's about new or existing rules

Comments

@RunDevelopment
Copy link
Owner

Some seemly innocent patterns can have a run time of O(n^2). This can be a vulnerability as pointed out here and further explained here.

"Even extremely simple regexes like /a+b/ show this O(n^2) behavior for inputs like 'a'*n." ('a'*n means n-many a characters.)

The purpose of this rule is to detect these patterns.

From what I've seen, the general rule seems to be: If there exists some set of paths AB*C in the regex R such that x = (L(A) ∩ L(B*)) \ ({ε} ∪ L(C)) is not the empty set, then R will take Ω(n^2) many steps to reject a word w ∈ x^n \ L(R).

Please note the Omega in the time complexity bound. This is not a typo. The backtracking algorithm might actually take more than O(n) steps to reject a suffix of the input string.

@RunDevelopment RunDevelopment added rule It's about new or existing rules new rule labels Oct 12, 2020
@RunDevelopment
Copy link
Owner Author

Already covered ota-meshi/eslint-plugin-regexp#159.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new rule rule It's about new or existing rules
Projects
None yet
Development

No branches or pull requests

1 participant