Closed Bug 1152680 Opened 9 years ago Closed 9 years ago

/a (.+)*a/ Regex causes AppHangB1 forever

Categories

(Firefox :: Untriaged, defect)

37 Branch
x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 696723

People

(Reporter: u523663, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; rv:37.0) Gecko/20100101 Firefox/37.0
Build ID: 20150402191859

Steps to reproduce:

It's caused when the regexp /a (.+)*a/ is used for replacing the text of a web page. It only works fine on pages with few text (like Facebook's homepage, for example).

Examples of websites where I experienced this hang:

http://www.tecmundo.com.br

https://www.google.com.br/search?q=abc

https://developer.mozilla.org/pt-BR/docs/Web/JavaScript

... and many others.


Note: I isolated the regexp the maximum I could, so that just the problematic part is provided. The original regexp I have that made me try to find what is wrong, is longer than that, but the result is the same (hang).


Actual results:

Firefox just freezes forever every time the regex is used, with an AppHangB1.


Expected results:

The expected is that it behave like every other regex, or like it behaves in lightweight pages.
I'm not sure what are the steps to reproduce. What uses this regexp? JS on a webpage? One of your add-ons? Something else?

Also see: https://developer.mozilla.org/en-US/docs/How_to_Report_a_Hung_Firefoxr
Flags: needinfo?(bruno_brilhante96)
"What uses this regexp?"
Anything that uses a script to find a string in the entire text of a webpage with any regexp similar to the /a (.+)*a/ pattern, either an add-on, an userscript, or a script executed in the console, i.e. a script executed externally, outside the webpage, that does this replacement on the webpage.
--------------------

Answering the questions in the link you provided:

Yes, Firefox uses <=50% on my dual-core CPU when this happens, however every day since when I open until when I close it, the consume is always this range when using normally.
Only Firefox hangs, everything outside it is completely responsive.
Flags: needinfo?(bruno_brilhante96)
Thanks for the clarification! Note that it's harder to see what you mean when you omit the precise steps to reproduce and jump to the conclusions; I'm still not 100% sure I understood you.

It looks like you're seeing bug 696723. The regular expression you found is very inefficient and takes very long time to run. The expected behavior is that it's interrupted by the "slow script" warning, but as bug 696723 says, it doesn't happen.

More info on exponential regexps: http://www.regular-expressions.info/catastrophic.html

Do you agree this is a duplicate of bug 696723?
Reading bug 696723 and the link you provided, and comparing with the bug I reported, I think they are the same bug. The only difference is that my case is a specific regex, but that is included in bug 696723, and if that is fixed, the bug I reported is also fixed (probably).
Thanks for confirming! Note (perhaps this is obvious after reading the links) that even with bug 696723 fixed, you still need to change your regexp to be more effective if you want it to run in reasonable time on all inputs.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.