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

ERROR: Maximum call stack size exceeded #5951

Open
PavelFil opened this issue Oct 20, 2024 · 1 comment
Open

ERROR: Maximum call stack size exceeded #5951

PavelFil opened this issue Oct 20, 2024 · 1 comment

Comments

@PavelFil
Copy link

uglify-js 3.19.3

test-js.zip
Run

uglifyjs test.js

Receive

ERROR: Maximum call stack size exceeded
    at [Symbol.hasInstance] (<anonymous>)
    at Object.prepend_comments (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21553:18)
    at doit (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21691:20)
    at AST_Binary.eval [as print] (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21686:13)
    at AST_Binary.eval [as _codegen] (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:22633:19)
    at doit (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21693:18)
    at AST_Binary.eval [as print] (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21686:13)
    at AST_Binary.eval [as _codegen] (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:22633:19)
    at doit (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21693:18)
    at AST_Binary.eval [as print] (eval at <anonymous> (/usr/local/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:21686:13)
@liquancss
Copy link

In this way, Uglify will call the AST_Binary.print methods recursively and can lead to stack overflow error.
You can try to replace doit() function call with it's actual code to reduce call frame.

// ./lib/output.js
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
        var self = this;
        stream.push_node(self);
        if (force_parens || self.needs_parens(stream)) {
            stream.with_parens(doit);
        } else {
            // doit()
            stream.prepend_comments(self);
            self.add_source_map(stream);
            self._codegen(stream);
            stream.append_comments(self);
        }
        stream.pop_node();

        function doit() {
            stream.prepend_comments(self);
            self.add_source_map(stream);
            self._codegen(stream);
            stream.append_comments(self);
        }
    });

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