Skip to content
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

Max call stack size exceeded under io.js #5

Closed
greim opened this issue Feb 8, 2015 · 6 comments
Closed

Max call stack size exceeded under io.js #5

greim opened this issue Feb 8, 2015 · 6 comments

Comments

@greim
Copy link

greim commented Feb 8, 2015

I only see this on io.js, not on node 0.11 or o.12.

/Users/foo/project/node_modules/mold-source-map/index.js:9
  var m = source.match(convert.commentRegex);
                 ^
RangeError: Maximum call stack size exceeded
    at String.match (native)
    at extractComment (/Users/foo/project/node_modules/mold-source-map/index.js:9:18)
    at new SourceMolder (/Users/foo/project/node_modules/mold-source-map/index.js:44:18)
    at exports.fromSource (/Users/foo/project/node_modules/mold-source-map/index.js:73:10)
    at Stream.end (/Users/foo/project/node_modules/mold-source-map/index.js:63:24)
    at _end (/Users/foo/project/node_modules/mold-source-map/node_modules/through/index.js:61:9)
    at Stream.stream.end (/Users/foo/project/node_modules/mold-source-map/node_modules/through/index.js:70:5)
    at Labeled.onend (/Users/foo/project/node_modules/browserify/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_readable.js:537:10)
    at Labeled.g (events.js:184:16)
    at Labeled.emit (events.js:119:20)
@thlorenz
Copy link
Owner

thlorenz commented Feb 8, 2015

This is odd as no recursiveness is going on there (except if applying the regex itself is).
Would you mind isolating this case as a separate script (outside of mold-source-map) and filing an issue with io.js?
I suppose it could be due to changed Regex evaluation in the newer v8 version but am not sure.

@greim
Copy link
Author

greim commented Feb 8, 2015

Here's my isolation code so far:

var fs = require('fs')
var convert = require('convert-source-map')
var source = fs.readFileSync('./source.js', 'utf8')
var patt1 = /^[ \t]*(?:\/\/|\/\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,(.+)(?:\*\/)?/mg
var patt2 = convert.commentRegex

try {
  var m = source.match(patt1)
  console.log('success with patt1')
} catch(ex) {
  console.log('fail with patt1')
  console.log(ex.message)
}

try {
  var m = source.match(patt2)
  console.log('success with patt2')
} catch(ex) {
  console.log('fail with patt2')
  console.log(ex.message)
}

...which outputs:

$ node test.js
success with patt1
fail with patt2
Maximum call stack size exceeded

What's weird is that patt1 is lifted directly from your own repo. Could it be related to it being accessed via a getter? I don't know. Unfortunately source is proprietary, but I'll try narrowing it down and fiddling some more.

@greim
Copy link
Author

greim commented Feb 10, 2015

I filed a bug on V8, however they pointed out this regex uses backtracking, and that a range error is expected behavior when running a backtracking regex against big strings.

Which is an argument against using regex to extract the source map comment in the first place, especially since concatenated source files (eg produced by browserify) are typically huge.

For example, maybe find indexOf('sourceMappingURL=data:') and go from there? Anyway, my 2¢

lidlanca added a commit to lidlanca/convert-source-map that referenced this issue Feb 11, 2015
issue reported: thlorenz/mold-source-map#5

If this change work you should be able to process a source string with the limit of the process memory and not the regexp stack.
I tested it with ~1gb of string.
please test cc: @greim
@greim
Copy link
Author

greim commented Apr 21, 2015

I had commented out mold-source-map in my project to avoid this, so had forgotten about this issue. But the error was recently re-introduced when a dependency was added to exorcist in my project. Maybe it would be resolved in both places if the convert-source-map dependency was upgraded in this project?

@greim
Copy link
Author

greim commented Apr 21, 2015

Weird. If I comment out some seemingly completely unrelated code, my build works just fine. The unrelated code is doing markdown parsing using https://www.npmjs.com/package/marked Which incidentally is very regex-driven.

@thlorenz
Copy link
Owner

@greim that is to be expected as marked is using regex to parse.
Maybe add this to the related io.js issue to show this isn't an isolated case but a somewhat serious regression?

In the meantime I'll upgraded convert-source-map and pushed a new patch release, but since the csm fix was also a patch you should already have gotten that fix in msm automatically.

Closing since issue is resolved from mold-source-map POV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants