Skip to content

Fixes StackOverflow in JavaDetectionEngine:resolveValues - #529

Closed
san-zrl wants to merge 3 commits into
mainfrom
fix/java-detection-engine-stack-overflow
Closed

Fixes StackOverflow in JavaDetectionEngine:resolveValues#529
san-zrl wants to merge 3 commits into
mainfrom
fix/java-detection-engine-stack-overflow

Conversation

@san-zrl

@san-zrl san-zrl commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #525. This is a bug in sonar-cryptography 1.6.1. It causes the CBOM generation to fail and thus breaks our CI pipeline. CBOM generation temporarily disabled.

  1. Added a tracker in JavaDetectionEngine:resolveValues that ends the recursion and exits the method if the symbol has been visited before.
  2. Changed repetitive log msg "Detected constructor definition has more then one argument..." to trace.

… log msg at debug lvl

Signed-off-by: san-zrl <san@zurich.ibm.com>
@san-zrl
san-zrl requested a review from a team as a code owner August 31, 2026 08:31
@san-zrl san-zrl added the bug Something isn't working label Aug 31, 2026
Signed-off-by: san-zrl <san@zurich.ibm.com>
@san-zrl
san-zrl requested a review from n1ckl0sk0rtge August 31, 2026 10:03
Signed-off-by: san-zrl <san@zurich.ibm.com>
@n1ckl0sk0rtge

n1ckl0sk0rtge commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Hi @san-zrl, thanks for tracking this down — the visited set is pointed at exactly the right method.

I dug into #525 as well and submitted the recursion fix in its own PR with a red-green test: #530. The test reproduces the exact alternating stack trace from the issue (a field initialized from another field, plus an assignment back). I would like to have a test for this behavior. Two notes on the difference to this PR:

  1. The visited set here is never released. Once a symbol is in the set, it stays there for the whole resolution. Two sibling branches that both go through the same shared variable (for example two array elements) then lose the second value. fix: stop endless recursion in resolveValues on assignment cycles #530 removes the symbol again in a finally block, so only real cycles are cut. The test also checks that the value still resolves through the cycle to the constant.
  2. Root cause of the flood: since e1fdab3 the engine resolves the arguments of every method call (for the detached call records), not only matched crypto calls. That is why both the recursion and the log noise only showed up in 1.6.1.

Suggestion to keep the pieces easy to review:

Happy to hear what you think.

@san-zrl

san-zrl commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Hi @n1ckl0sk0rtge - makes sense. If I re-enable the CBOM generation the build for this PR will fail. But this is okay, since only the trivial log change is left.

@san-zrl

san-zrl commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

I'll close this PR an file another with log change.

@san-zrl san-zrl closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 1.6.1 (compared to 1.6.0): StackOverflowError and excessive logging

2 participants