Skip to content

fix(JNI): resolve JNI code safety issues in native layer#17

Draft
Federico2014 wants to merge 5 commits intotronprotocol:masterfrom
Federico2014:feature/improve_zksnark
Draft

fix(JNI): resolve JNI code safety issues in native layer#17
Federico2014 wants to merge 5 commits intotronprotocol:masterfrom
Federico2014:feature/improve_zksnark

Conversation

@Federico2014
Copy link
Copy Markdown

Summary

This PR fixes critical JNI code safety issues in the native C++ layer.

Changes

LibrustzcashJNIImpl.cpp (25 functions fixed)

  • Replace unused <iostream> with <cstring>
  • Fix null check ordering (move BEFORE function calls)
  • Add proper error cleanup with JNI_ABORT on error paths
  • Use modern C++ casts (reinterpret_cast, static_cast, const_cast)
  • Replace NULL with nullptr
  • Fix string length API (strlen vs GetStringLength)

LibsodiumJNIImpl.cpp (8 functions fixed)

  • Replace unused <iostream> with <cstring> and <new>
  • Use new (std::nothrow) to prevent unhandled exceptions
  • Add comprehensive null pointer checks and error cleanup
  • Modern C++ style casts

CMakeLists.txt

  • Add macOS-specific libc++ include path for Clang
  • Support architecture-specific install destinations

README.md

  • Update build instructions

Testing

  • All 33 tests pass

@Federico2014 Federico2014 marked this pull request as draft March 26, 2026 02:59
@Federico2014
Copy link
Copy Markdown
Author

This pr mainly fix the issue: #16.

3for and others added 3 commits March 26, 2026 12:06
- update cpp/CMakeLists.txt to derive the Rust target from the active CMake architecture
- build librustzcash with the matching Cargo target and link the correct target/<triple>/release archive
- reject unsupported universal macOS builds to avoid mixed-architecture artifacts
- re-sign the installed macOS JNI library after make install so Maven tests can load it without the forked JVM being killed
- replace JDK-internal HexBin usage in LibsodiumTest and LibrustzcashTest with local hex decoders for JDK 17 compatibility
- refresh README build instructions for Apple Silicon and clarify that Maven package/test commands should be run from the project root
… compatible

- extract shared HexBin decoder into src/test/java/org/tron/common/zksnark/HexBin.java
- remove duplicated HexBin inner classes from LibrustzcashTest and LibsodiumTest
- replace COMMAND_ERROR_IS_FATAL in cpp/CMakeLists.txt with RESULT_VARIABLE checks
  so make install stays compatible with CMake 3.10.2
- refresh bundled macOS arm64 native library
feat(arm64_macos): stabilize Apple Silicon build and JDK 17 test flow
@Federico2014 Federico2014 marked this pull request as ready for review March 26, 2026 07:41
@Federico2014 Federico2014 marked this pull request as draft March 31, 2026 09:01
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.

2 participants