New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RangeError in some scenarios calling RegEx #759
Comments
Parsing a regular expression causing a call stack exceeded error is definitely more likely a v8 bug. A quick peek at the v8 issue tracker doesn't show any bugs relating to that related You should file a bug against v8 - it definitely sounds like a regression they'll address. |
I'm not sure but this may be triggered because |
@micnic This is pretty much also what Object.defineProperty does https://github.com/v8/v8/blob/8851bf83a938f79ab522b829261157396d9988aa/src/v8natives.js#L1170 (except for when proxies are involved but this is not the case here). |
@benjamingr , you are right, then it's definitely a v8 issue. @greim , it would be great if you could reproduce this bug with a smaller (and open) input for |
As pointed out by others, this is essentially a V8 issue. I'm curious though, does passing |
Here's code that reproduces it for me: var patt = /(?:\/\/|\/\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,((?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?)(?:[ \t]*\*\/)?$/mg;
var source = '//# sourceMappingURL=data:application/json;base64,'
var len = 4473955
while (source.length < len){
source += 'ICAgICAgICApXG4gICAgICAgIClcbiAgICAgIClcbi'
}
source = source.substring(0,len)
patt.test(source) I narrowed it doen to Error output:
[edit] It's also strange that the above error output shows the |
I tried In visual studio, I added the And I was able to run the replication code @greim provided without |
I did notice that munging the regex ever so slightly in order to prevent a match makes the error go away. In other words changing this:
...to this:
(BTW I'm on OS X 10.10.2) |
What is your system stack size limit. |
The error also happens on Chrome. It is definitely a v8 issue. |
@targos that settles it then. V8 has also accepted the bug. |
Stack size is 8192. In the v8 bug it was pointed out this is due to regex backtracking and isn't really a bug, although I think the error reporting could be a little clearer. In any case I'll close this later today unless someone disagrees or thinks there's a reason to keep it open. Or if someone else closes it that's fine. |
This is definitely a regression since the exact same scenario works with nodes that use older v8 versions. I'd like to introduce the v8 label for similar issues @mikeal but can't myself do so. This label will help the v8 team find issues they can help us with. I feel we need to stay on top of these regressions as code that ran fine with previous node versions now suddenly and now suddenly doesn't work anymore is not going to benefit io.js adoption. @beanieboi @targos are you going to stay on top of this bug and make sure that it gets solved in v8 and/or io.js users are aware of this issue until it gets fixed? |
@thlorenz As noted in the v8 issue tracker, this is as designed. //v8/src/regexp-stack.h
static const size_t kMaximumStackSize = 128 * MB; //default 64 There are some inconsistencies between versions and sometimes the same process, more likely due to working on the limit of the stack dynamic allocation. and some external factors. |
The error I was originally seeing goes away with this slight modification to the regex: var works = /^[ \t]*\/(?:\/|\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,(..*)$/mg
var fails = /^[ \t]*\/(?:\/|\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,(.+)$/mg Anybody with strong regex foo know why the one would cause a RangeError but not the other? |
Those regular expressions behave really strangely...
|
@bnoordhuis it is apparently because of the Btw : |
@targos regular expressions need a lot of backtracking to perform matches and a call stack size exceeded error should not be too surprising. @greim this has nothing to do with being strong with regex - This is pretty much all explained in the issue tracker issue which raises an interesting issue -@thlorenz what is the policy on v8 won't-fix issues? |
I'm not the right person to ask as I honestly don't know. |
Also, I can't reproduce this particular error in isolation, using the same regex on the same string. Even if I fill most available memory with other stuff. for (var i=0, amount=80000000, arr=Array(amount); i<amount; i++) arr[i] = i
var source = require('fs').readFileSync('./source.js', 'utf8')
source.match(/(?:\/\/|\/\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,(.+)$/mg) Using a number much higher than Anyway, if this is just risk of doing business with v8 regex that's fine, I don't want to keep spamming this thread. Mainly wanted to rule out some bug in newer v8 that might make life hard for iojs adopters. |
@bnoordhuis @targos - Apparently regex with |
Update: As mentioned previously, I couldn't reproduce this in isolation; it would only occur during my gulp build. Upon further investigation, commenting out some seemingly unrelated code in my gulp build which was using marked to process markdown, prevents the error. Unfortunately I still can't reproduce in isolation, but I'm removing things from the gulp build to try to narrow it down. |
On io.js 2.2.1 and 2.3.1 (by the time of writing it's the latest) I have this error: ``` RangeError: Maximum call stack size exceeded at String.match (native) ``` It happens only on the second pass while karma is working (auto watching and reruns the specs). For more details read this issue: nodejs/node#759 Similar issues: thlorenz/convert-source-map#10 thlorenz/convert-source-map#11 Looks like this related to optimizations in V8 regex engine: http://blog.chromium.org/2009/02/irregexp-google-chromes-new-regexp.html Simply changing from `.+` to `..*` equivalent rule fixes an issue with match function.
On io.js 2.2.1 and 2.3.1 (by the time of writing it's the latest) I have this error: ``` RangeError: Maximum call stack size exceeded at String.match (native) ``` It happens only on the second pass while karma is working (auto watching and reruns the specs). For more details read this issue: nodejs/node#759 Similar issues: thlorenz/convert-source-map#10 thlorenz/convert-source-map#11 Looks like this related to optimizations in V8 regex engine: http://blog.chromium.org/2009/02/irregexp-google-chromes-new-regexp.html Simply changing from `.+` to `..*` equivalent rule fixes an issue with match function.
On io.js 2.2.1 and 2.3.1 (by the time of writing it's the latest) I have this error: ``` RangeError: Maximum call stack size exceeded at String.match (native) ``` It happens only on the second pass while karma is working (auto watching and reruns the specs). For more details read this issue: nodejs/node#759 Similar issues: thlorenz/convert-source-map#10 thlorenz/convert-source-map#11 Looks like this related to optimizations in V8 regex engine: http://blog.chromium.org/2009/02/irregexp-google-chromes-new-regexp.html Simply changing from `.+` to `..*` equivalent rule fixes an issue with match function.
it is necessary for huge files. Related issues v8 https://bugs.chromium.org/p/v8/issues/detail?id=3878 nodejs nodejs/node#759 convert-source-map https://travis-ci.org/thlorenz/convert-source-map/jobs/53989952 gulp-sourcemaps gulp-sourcemaps#73
it is necessary for huge files. Related issues v8 https://bugs.chromium.org/p/v8/issues/detail?id=3878 nodejs nodejs/node#759 convert-source-map https://travis-ci.org/thlorenz/convert-source-map/jobs/53989952 gulp-sourcemaps gulp-sourcemaps#73
Example of the error:
It doesn't seem like mold-source-map or its deps are doing anything wrong. Here's an isolated test case: thlorenz/mold-source-map#5 (comment)
It doesn't happen on node 0.12 or 0.11. I wondered if this was a difference in newer v8? Unfortunately
./source.js
(noted in the linked code) is proprietary, but it's 125k lines long, trailed by a 6.5 million character long one-liner source map comment.The text was updated successfully, but these errors were encountered: