Vscode: Regex Find can cause VS Code to Freeze

Created on 17 Jul 2017  路  22Comments  路  Source: microsoft/vscode

  • 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

bug editor-find freeze-slow-crash-leak integrated-terminal upstream-issue-linked

Most helpful comment

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!

All 22 comments

It also happens with: 1.15.0-insider

I close it by accident. This is a real issue.

Really good catch! Unfortunately search viewlet shares the same issue.

cc @roblourens

The reason for the hang is the regex """(.*?\n?)+?""" has Catastrophic Backtracking, you can run into the same hang/100% CPU when executing this regex agains that snippet.py file in any browser.

We should have some timeout here to avoid the hang however.

@rebornix it probably only impacts the search viewlet when the file is open, right? I think Rust's regex engine is not susceptible to this. So it would be fixed by any fix to the editor.

@roblourens yes exactly as you said. It should just be a fix in the editor side.

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
(.*
   ^

I have another case of a regex search that hangs VS Code: /\*(.*\n?)*\*/.

  • Pasting the regex immediately hangs VS Code, and a window appears after a few seconds, suggesting to reopen the window.
  • Typing the regex manually will hang when typing the fourth * character specifically (I reproduced it many times to make sure it was this specific character hanging), so: /\*(.*\n?)*\ works, then as you type the * right after that, it hangs.

This is on VS Code 1.21.1, on Windows 10, both x64.

I found an another one that hangs. (.*)\(\d*\

  • VSCode Version: 1.22.2
  • OS Version: Windows 10 1709

I attempted to turn a rather large HTML file (577KB) into a CSV containing only data from that file. I can't share that file due to privacy reasons.

  1. Press CTRL+H for search and replace
  2. Enable regex and type in (.*)\(\d*\ and possibly punch in another space after it

There's about 25% CPU activity after it hangs, but I've been waiting a couple of minutes now. A regex shouldn't ever hang the whole editor.

Does this issue occur when all extensions are disabled?: Yes

Input order:

  1. input \s19:.*
  2. insert . to start
  3. vscode freezed

Input order:

  1. input \s19:.*
  2. insert . to start
  3. vscode freezed

Vscod Version: 1.31.1
Os: mac 10.14.3

Curious that it's such a problem since other editors like Sublime don't have a problem with highlighting regex matches... Why is newline such an issue? Shouldn't it be just another character?

Curious that it's such a problem since other editors like Sublime don't have a problem with highlighting regex matches... Why is newline such an issue? Shouldn't it be just another character?

Actually I've tested my search in Sublime and there I have the following messages (but no crash!):

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

I am running into this, too, for Find in a single file (not the global find/replace). I'm encountering the issue simply by using a pipe character (|) in my RegEx, when I have not yet populated characters after the pipe character. If I try enter something like

element|

(eventually intending to type element|getElement), VSCode freezes up, before I've even hit "Enter" to do the Find.

This is on VSCode version 1.39.2, on Max OSX Mojave (v10.14.6).

Version: 1.41.1 (user setup)
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:58:56.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

and still

VSCodeProblem

@Fadavvi please open a new issue, I can't repro it. I'm curious whether it happens without the "whole word" toggle enabled, or in a shorter file.

@Fadavvi please open a new issue, I can't repro it. I'm curious whether it happens without the "whole word" toggle enabled, or in a shorter file.

OK. I'll open a new issue. It happen only on some special files. I can't find similarity of files!

I am running into this, too, for Find in a single file (not the global find/replace). I'm encountering the issue simply by using a pipe character (|) in my RegEx, when I have not yet populated characters after the pipe character. If I try enter something like

element|

(eventually intending to type element|getElement), VSCode freezes up, before I've even hit "Enter" to do the Find.

This is on VSCode version 1.39.2, on Max OSX Mojave (v10.14.6).

+1 to this on VSCode 1.45.0 on Linux x64 5.6.0-1-amd64 (Debian)

Very simple regex to reproduce: (x|)

Looks to be fixed in 1.45.1 for me. @Artemis21 can you repro in 1.45.1?

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!

This https://twitter.com/schuay/status/1325715124930420736 looks promising for current case, but wonder if it will be applicable.

Details in Chromium bug tracker: Issue 10765: Tracking bug: Non-backtracking regexp execution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DovydasNavickas picture DovydasNavickas  路  3Comments

VitorLuizC picture VitorLuizC  路  3Comments

trstringer picture trstringer  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

lukehoban picture lukehoban  路  3Comments