X Tutup
Skip to content

Prevent JNI Variant conversion stack overflow#110452

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
limbonaut:prevent-jni-variant-conv-stack-overflow
Sep 19, 2025
Merged

Prevent JNI Variant conversion stack overflow#110452
Repiteo merged 1 commit intogodotengine:masterfrom
limbonaut:prevent-jni-variant-conv-stack-overflow

Conversation

@limbonaut
Copy link
Contributor

While I was testing a plugin with Godot on Android, I triggered a stack overflow by trying to convert a Variant with cyclic references. This PR prevents crashes by adding a call depth guard, similar to how it's handled in other places in the codebase.

@limbonaut limbonaut requested a review from a team as a code owner September 12, 2025 11:29
@limbonaut limbonaut force-pushed the prevent-jni-variant-conv-stack-overflow branch from 6ed12c7 to da1b8e2 Compare September 12, 2025 11:36
@AThousandShips AThousandShips added this to the 4.6 milestone Sep 12, 2025
Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix!

@m4gr3d
Copy link
Contributor

m4gr3d commented Sep 12, 2025

@limbonaut Could you use https://github.com/dsnopek/javaclasswrapper-test to validate that the fix doesn't introduce a regression.

@dsnopek @syntaxerror247 We should look into whether we can integrated the javaclasswrapper-test into a regression test that's run by the CI.

@limbonaut limbonaut force-pushed the prevent-jni-variant-conv-stack-overflow branch from da1b8e2 to 476b901 Compare September 14, 2025 10:52
@limbonaut
Copy link
Contributor Author

I ran the tests, and they all passed! But I’ve added an extra test to check if variant conversion is safe from stack overflow, and it still crashed. I’m updating the PR because there was an issue in my implementation, leaving jvalue uninitialized and still leading to crash. Thanks for pointing me towards those tests, @m4gr3d! I’ll also make a PR for the test repo to add the SO test.

Now, all the tests are passing, including the new one for stack overflow:
Screenshot 2025-09-14 at 13 02 42

@Repiteo Repiteo merged commit 78d1539 into godotengine:master Sep 19, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 19, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup