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

RangeError: Maximum call stack size exceeded #89

Closed
hatRiot opened this issue Sep 2, 2017 · 7 comments
Closed

RangeError: Maximum call stack size exceeded #89

hatRiot opened this issue Sep 2, 2017 · 7 comments
Labels

Comments

@hatRiot
Copy link

hatRiot commented Sep 2, 2017

Seems related to issue #86 , but not on Android.

> npm view javascript-obfuscator version
0.11.0
> node --version
v8.4.0

The error seems to manifest itself with long strings:

     BinaryExpression: function (expr, precedence, flags) {
                                   ^
RangeError: Maximum call stack size exceeded
    at CodeGenerator.BinaryExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:1837:36)
    at CodeGenerator.generateExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:2648:28)
    at CodeGenerator.BinaryExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:1845:29)
    at CodeGenerator.generateExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:2648:28)
    at CodeGenerator.BinaryExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:1845:29)
    at CodeGenerator.generateExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:2648:28)
    at CodeGenerator.BinaryExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:1845:29)
    at CodeGenerator.generateExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:2648:28)
    at CodeGenerator.BinaryExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:1845:29)
    at CodeGenerator.generateExpression (/node_modules/javascript-obfuscator/node_modules/escodegen-wallaby/escodegen.js:2648:28)

Oddly, this same code works on Node v8.0, but not Node v8.4, so perhaps it isn't related to javascript-obfuscator directly?

Config:

var config = {
    compact: true,
    controlFlowFlattening: false,
    controlFlowFlatteningThreshold: 0.75,
    deadCodeInjection: true,
    deadCodeInjectionThreshold: 0.4,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    mangle: false,
    reservedNames: [],
    rotateStringArray: true,
    seed: 0,
    selfDefending: false,
    sourceMap: false,
    sourceMapBaseUrl: '',
    sourceMapFileName: '',
    sourceMapMode: 'separate',
    stringArray: true,
    stringArrayEncoding: true,
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false
}

You can reproduce this by generating a script with a large, multiline string:

> cat generate.py 
data = "A"*200000
data = [data[i:i+75] for i in range(0, len(data), 75)]
chunked = '+\n'.join(["\"{0}\"".format(x) for x in data])
with open('output.js', 'w+') as f:
    f.write("var test = {0};".format(chunked))

And then running output.js through javascript-obfuscator.

@sanex3339 sanex3339 added the bug label Sep 2, 2017
@sanex3339
Copy link
Member

Hi! Can you provide input source code that will passed to obfuscator (generated by script above)?

@hatRiot
Copy link
Author

hatRiot commented Sep 2, 2017

The output of the script is just a long, multiline string of the form:

var test = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
..............

It would be too long to reproduce in its entirety here. This script is fed into a small script that reads it and invokes Javascript-Obfuscator:

var jsob = require('javascript-obfuscator');
var fs = require('fs');

var config = {
    compact: true,
    controlFlowFlattening: false,
    controlFlowFlatteningThreshold: 0.75,
    deadCodeInjection: true,
    deadCodeInjectionThreshold: 0.4,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    mangle: false,
    reservedNames: [],
    rotateStringArray: true,
    seed: 0,
    selfDefending: false,
    sourceMap: false,
    sourceMapBaseUrl: '',
    sourceMapFileName: '',
    sourceMapMode: 'separate',
    stringArray: true,
    stringArrayEncoding: true,
    stringArrayThreshold: 0.75,
    unicodeEscapeSequence: false
}

if(process.argv.length <= 1){
    process.exit();
}

var unobf_data = fs.readFileSync(process.argv[2], 'utf8');
var obf = jsob.obfuscate(unobf_data, config);
fs.writeFileSync(process.argv[2], obf);

@sanex3339
Copy link
Member

How many lines i should create to reproduce?

@hatRiot
Copy link
Author

hatRiot commented Sep 2, 2017

My script generates 200k characters and breaks them into 75 character lines, so about 2667 lines should trigger the issue.

@hatRiot
Copy link
Author

hatRiot commented Oct 19, 2017

FYI it looks like this may be a bug in escodegen. There's an open issue from 2016 here that looks to be the exact same thing.

Feel free to close this if you'd like.

@sanex3339
Copy link
Member

Yep, look's like it related to escodegen.

@D00Movenok
Copy link

Hi! Using node v20.3.1 and javascript-obfuscator 4.0.2, got the same issue.
As I see, javascript-obfuscator now uses personal fork of escodegen. Will It be fixed in the future?

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

No branches or pull requests

3 participants