Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Atom hang with 100% cpu when regex engine does catastrophic backtracking #557

Open
jeancroy opened this issue Oct 14, 2015 · 1 comment
Open
Labels

Comments

@jeancroy
Copy link
Contributor

Buffer: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Search: [A-Z0-9]+([A-Z0-9._%+-]*)+@[A-Z0-9.-]+\.[A-Z]{2,4}
Options: Regex, Case insensitive, No word Boundary.

Search make atom freeze with 100% CPU, no decoration or large buffer involved. After some time, 'editor is unresponsive' popup appears.

Example regex is a real life (bad) email regex found on stackoverflow. Problem start while trying to match @. Because search can't find @, regex backtrack. The problem then is ([]*)+ pattern which basically mean: any amount of group containing any amount of character. And there's ton of permutation of that ! Nevertheless regex engine will examine every on of them just in case one permutation will free up a @.

Maybe the suggestion to use a separate thread for searching is not all bad.

One interesting bit of information is that Atom use oniguruma for syntax coloring, which support async search with callback. This might be a relatively cheap route for implementing search in a separate thread.

Alternative one could be to try to sanitize the regex.

@alexchandel
Copy link

This would be fixed by #571, since oniguruma handles this much better.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants