The regex literal /^(.){1,64}$/ throws a JSMSG_REGEXP_TOO_COMPLEX ("regular expression is too complex") when parsed

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
RESOLVED WORKSFORME
8 years ago
7 years ago

People

(Reporter: Ben Zanin, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

725.06 KB, application/octet-stream
Details
(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
Build Identifier: http://www.mozilla.com/products/download.html?product=firefox-4.0b4&os=win&lang=en-US

While debugging a webmail product at the office under Windows Vista, I noticed that it loaded correctly under every version of Chrome, Internet Explorer, and Firefox that I tested, except for Firefox 4.0b4.  The error console showed "regular expression is too complex" but included no other information such as the context in which the error originated or the line number in a given file.

I eventually tracked it down to the regex literal /^(.){1,64}$/ : when the parser encountered this awful thing, it choked and killed the expected execution path of the other, saner parts that followed it.

I suspect that this is related to YARR (564953), but I haven't yet tracked down the precise location of the error.

Reproducible: Always

Steps to Reproduce:
1. paste this into the address bar: javascript:(function(){x=/^(.){1,64}$/;alert("foo")})()

2. press enter
Actual Results:  
In Firefox 4.0b4 running under Vista 32-bit, this errors out and throws a "regular expression is too complex" note into the error console, which I believe to be a JSMSG_REGEXP_TOO_COMPLEX.

Expected Results:  
I would expect "foo" to appear in an alert box.
Assignee: nobody → general
Component: General → JavaScript Engine
OS: Windows Vista → All
Product: Firefox → Core
QA Contact: general → general
Hardware: x86 → All
Version: unspecified → Trunk
Confirmed on Vista/64.
Assignee: general → cdleary
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Er, rather, Win7/64.

Comment 3

8 years ago
I have the same error with another regular expression. Should I open a separate bug?
(As for the RegExp described here, I don't get the error, is it fixed or is it only on windows?)


Here is my RegExp (you can just paste it in firebug and it will throw the error):
/^[a-zA-Z0-9_.+-=?^#]{1,64}@(([a-zA-Z0-9-]){1,251}.){1,252}[a-zA-Z0-9]{2,4}$/

So, as for the description of this bug:

Steps to Reproduce:
1. paste this into the address bar:
javascript:(function(){x=/^[a-zA-Z0-9_.+-=?^#]{1,64}@(([a-zA-Z0-9-]){1,251}.){1,252}[a-zA-Z0-9]{2,4}$/;alert("foo")})()

2. press enter
Actual Results:  
In Firefox 4.0b10pre running under Ubuntu 10.10 32-bit, it throws a "regular expression is too complex" error in the console (without a line number).

Expected Results:  
I would expect "foo" to appear in an alert box.
Nominating for softblocking, checking it out now.
blocking2.0: --- → ?
The location "javascript:(function(){x=/^(.){1,64}$/;alert("foo")})()" works fine on my Win7/32 machine with the nightly. Ben, are you still able to reproduce this?
(In reply to comment #3)

Yann, I've created bug 633677 for your issue.
Removing blocking nomination until I can get STR / confirmation this is still broken.
blocking2.0: ? → ---
Assignee: cdleary → general
Status: ASSIGNED → UNCONFIRMED
Ever confirmed: false

Comment 8

7 years ago
I have similar problem with this line of code:

"<>2222222222222222".match(/<(.|[^.])*>/);

With it I get "regular expression is too complex" error in Firefox 4.0 release. Should I open separate ticket for it?
(In reply to comment #8)
> I have similar problem with this line of code:
> 
> "<>2222222222222222".match(/<(.|[^.])*>/);
> 
> With it I get "regular expression is too complex" error in Firefox 4.0 release.
> Should I open separate ticket for it?

Please do.

Comment 10

7 years ago
I have the same to problem. I'm working on a workaround for detecting large float arrays in JSON object as they cannot be initialized (see bug 667527).

I want to replace:
"vertices",[23.34,231.32,23.32, ... ,231.23]
with:
"vertices","23.34,231.32,23.32, ... ,231.23"
as I can create the float array using this splitted string.

The following regex is used for this:
var regExLongArray = /\"(vertices|indizes)\":\[((?:[-+]?[0-9]*\.?[0-9]*,){1000,}[^\]]*)\]/g;
text = text.replace(regExLongArray, '"$1":"$2"');

In short: Do this only if key is "vertices" or "indices". 
Find at least 1000 float inside an array.
Back reference the key and all data.

////

I did some testing with this and found out the the bug is not depending on the amount of data too be analysed. 

it works fine analysing:
var json_small = '{"vertices":[232.23, 232.23, 232.23]}';
but as I want to parse a string of about 5MB size it crashes.

I attached a test case to reproduce. 
Tested on Firefox 4 and 5, same behavior.

Works fine on other browsers (Chrome, IE, Safari, Opera)

Comment 11

7 years ago
Created attachment 542471 [details]
Testcase
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.