Skip to content

fix: add recursion guard to traceSymbol to prevent StackOverflow on mutual assignment cycles#401

Open
Ayush-Patel-56 wants to merge 3 commits intocbomkit:mainfrom
Ayush-Patel-56:fix/issue-400-recursion-guard
Open

fix: add recursion guard to traceSymbol to prevent StackOverflow on mutual assignment cycles#401
Ayush-Patel-56 wants to merge 3 commits intocbomkit:mainfrom
Ayush-Patel-56:fix/issue-400-recursion-guard

Conversation

@Ayush-Patel-56
Copy link
Copy Markdown

@Ayush-Patel-56 Ayush-Patel-56 commented May 6, 2026

Summary

Fixes #400

Note: depends on #390. Once that merges this PR will show only the 4 files relevant to the recursion guard.

  • Adds a visited: Set<Symbol> overload to traceSymbol in both PythonDetectionEngine and JavaDetectionEngine
  • The public overload delegates to the private one with new HashSet<>(), so all call sites are unchanged
  • On the first revisit of any symbol the guard returns the current symbol immediately, terminating the cycle

Test plan

  • Issue400RecursionGuardTest (Python) — verifies a mutual assignment cycle (alg = intermediary; intermediary = alg) completes within 10 s without StackOverflowError and still detects AES
  • Issue8IntermediaryVariableTest (Python) — regression: single-hop indirection still resolves correctly
  • Issue8IntermediaryVariableTest (Java) — regression: intermediary variable chain still resolves correctly
  • Issue8MethodReceiverTest (Java) — regression: method-receiver intermediary still resolves correctly

Signed-off-by: Ayush Patel <ayushpatel2731@gmail.com>
Signed-off-by: Ayush Patel <ayushpatel2731@gmail.com>
… on mutual assignment cycles

Signed-off-by: Ayush Patel <ayushpatel2731@gmail.com>
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.

Add recursion guard to traceSymbol in Java and Python detection engines

1 participant