Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 20, 2025

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 used nextPath.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:

path.remove();
nextPath.replaceWithMultiple(statements);  // <- Missing path.skip() after this
self.setChanged();

After calling replaceWithMultiple(), the Babel traversal would continue and potentially re-process the newly inserted statements, leading to infinite recursion if those statements matched the same control flow patterns.

Solution

Added path.skip() immediately after the replaceWithMultiple() call to prevent re-traversal of the modified AST section:

path.remove();
nextPath.replaceWithMultiple(statements);
path.skip();  // <- Prevents re-traversal and infinite recursion
self.setChanged();

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

  • antiTamperRemover.ts: No changes needed - only uses path.remove() operations which don't require path.skip()
  • Other transformation files: Not mentioned in the issue scope, keeping changes minimal as requested

Testing

  • ✅ All existing tests pass
  • ✅ TypeScript compilation succeeds
  • ✅ Custom test confirms ControlFlowRecoverer runs without infinite loops
  • ✅ No regressions detected

Change Summary

  • Files modified: 1 file
  • Lines added: 1 line
  • Lines deleted: 0 lines
  • Net change: Minimal surgical fix

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.

Copilot AI and others added 2 commits June 20, 2025 20:31
Co-authored-by: CharlieEriksen <1864062+CharlieEriksen@users.noreply.github.com>
…prevent infinite recursion

Co-authored-by: CharlieEriksen <1864062+CharlieEriksen@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix infinite recursion in AST traverse visitors by adding path.skip() after replaceWith/replaceWithMultiple Fix infinite recursion in Babel AST traversal by adding path.skip() after replaceWithMultiple Jun 20, 2025
Copilot finished work on behalf of CharlieEriksen June 20, 2025 20:36
@ben-sb
Copy link
Owner

ben-sb commented Jun 21, 2025

Can you provide a sample that triggers the bug you are trying to fix?

@CharlieEriksen
Copy link

I apparently made a mistake and created an issue in the wrong repo. This was meant to be on my fork. So you can close this PR.

I made a bunch of fixes over at https://github.com/CharlieEriksen/obfuscator-io-deobfuscator, to fix a bunch of performance issues. Feel free to pull over anything you want.

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

Successfully merging this pull request may close these issues.

3 participants