question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regex Find can cause VS Code to Freeze

See original GitHub issue
  • VSCode Version: 1.14.1
  • OS Version: Mac OSX Sierra 10.12.5 (16F73)

Steps to Reproduce:

  1. code --disable-extensions
  2. File->New File
  3. Paste file from here: snippets.py (it happens with other files, but this is a simple example)
  4. Edit->Find """(.*?\n?)+?""" regex
  5. Try to remove the last ? from the regex.
  6. The editor freezes at this point
  7. Code Helper goes to 100% CPU.

Result: image

Reproduces without extensions: Yes

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:27
  • Comments:35 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
ndbroadbentcommented, Jun 6, 2020

I’m using VS Code 1.45.1, and I’ve just found another regex that will cause VS Code to freeze: "([^]+\n)+"

I’ve reproduced this with some minimal examples: https://gist.github.com/ndbroadbent/bb5e246b05488296576ee3dc39d40e38

(I’ve tested these with code --disable-extensions to disable all extensions.)

One example freezes my computer for about 1-2 seconds. The other example just has a few extra lines, but it looks like it causes a huge exponential increase in complexity and freezes VS Code forever.

It would be a really good idea to add a simple timeout so that we don’t accidentally freeze the editor.

These error messages from Sublime would be even better:

ERROR: Regex exhausted stack searching file
ERROR: Regex complexity too high searching file

Thanks!

4reactions
Spowncommented, Mar 20, 2018

Another case:

Steps:

  1. Have a file with content
t({phrase: 'mail_text_q', locale: 'ru-RU'}, mailCtx)+'\n'+
t({phrase: 'mail_text_m', locale: 'ru-RU'}, mailCtx)+'\n'+
  1. call search widget
  2. set to RegEx
  3. input (.*+'\n'+
  4. try to add ) after the third character
(.*
   ^
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regex search causes VS-Code to crash on macbook
I don't believe that is supported in vscode search across files. In any case, your original regex froze vscode on my Windows machine, ......
Read more >
Catastrophic backtracking - The Modern JavaScript Tutorial
Catastrophic backtracking. Some regular expressions are looking simple, but can execute a veeeeeery long time, and even “hang” the ...
Read more >
Bracket pair colorization 10000x faster - Visual Studio Code
To make this easier, in 2016, a user named CoenraadS developed the awesome Bracket ... This ensures that the UI does not freeze,...
Read more >
Use regular expressions - Visual Studio (Windows)
Purpose Expression Example Match any single character in a set b matches "ba", "bb", and "bc" Escape the character following the backslash \ \^ matches...
Read more >
Regular expression Denial of Service - ReDoS
An attacker can then cause a program using a Regular Expression (Regex) to ... (if needed) until a match is found (or all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found