Fix infinite recursion in Babel AST traversal by adding path.skip() after replaceWithMultiple #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Stack overflow was occurring due to infinite recursion in Babel's AST traversal during transformation passes, specifically in
controlFlowRecoverer.ts
. When the control flow recovery transformation usednextPath.replaceWithMultiple(statements)
to replace AST nodes, the traversal would re-visit the newly inserted nodes, potentially matching the same transformation patterns and causing infinite loops.Root Cause
The issue was in
src/deobfuscator/transformations/controlFlow/controlFlowRecoverer.ts
at line 81:After calling
replaceWithMultiple()
, the Babel traversal would continue and potentially re-process the newly insertedstatements
, leading to infinite recursion if those statements matched the same control flow patterns.Solution
Added
path.skip()
immediately after thereplaceWithMultiple()
call to prevent re-traversal of the modified AST section:This follows the standard Babel pattern of calling
path.skip()
after AST mutations to prevent the traversal from revisiting the modified parts of the AST tree.Analysis of Other Files
path.remove()
operations which don't requirepath.skip()
Testing
Change Summary
This change resolves the stack overflow issue while maintaining all existing functionality and following Babel best practices for AST transformation.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.