# LSPosed A16 Fix — JNINativeInterface Runtime Size Mismatch ## The Bug Vector v2.0 (and JingMatrix v1.10+) crashes zygote64 on Android 16 with: ``` JNI DETECTED ERROR IN APPLICATION: negative buffer capacity in NewDirectByteBuffer from int com.android.internal.os.Zygote.nativeForkSystemServer ``` Magisk auto-rolls-back Zygisk. Modules never inject. ## Root Cause `zygisk/src/main/cpp/ipc_bridge.cpp:557`: ```cpp memcpy(&native_interface_hook_, env->functions, sizeof(JNINativeInterface)); ``` - `sizeof(JNINativeInterface)` = compile-time constant (NDK 26 = ~2376 bytes) - Android 16 ART added new JNI functions → runtime structure is LARGER - `memcpy` truncates the table → garbage function pointers for new JNI calls - `reserved0` stores the actual runtime size (set by ART) but truncated copy preserves it - ART's `SetTableOverride` sees correct size → calls garbage → crash ## Fix Two files changed: ### `zygisk/src/main/cpp/include/ipc_bridge.h` line 167 ```diff - JNINativeInterface native_interface_hook_{}; + JNINativeInterface* native_interface_hook_ = nullptr; + size_t table_size_ = 0; ``` ### `zygisk/src/main/cpp/ipc_bridge.cpp` lines 555-566 ```cpp // OLD (broken): memcpy(&native_interface_hook_, env->functions, sizeof(JNINativeInterface)); // NEW (fixed): table_size_ = (size_t)env->functions->reserved0; if (table_size_ == 0 || table_size_ < sizeof(JNINativeInterface)) table_size_ = sizeof(JNINativeInterface); native_interface_hook_ = (JNINativeInterface*)malloc(table_size_); memcpy(native_interface_hook_, env->functions, table_size_); // ... change . to -> for native_interface_hook_ references ``` ## Build & Deploy ```bash git clone --depth 1 --recursive https://github.com/JingMatrix/LSPosed.git cd LSPosed bash apply_a16_fix.sh . # from ~/tmp/xhs_lsposed_a16_fix/ export ANDROID_HOME=/path/to/sdk ./gradlew :zygisk:assembleRelease # Output: zygisk/build/outputs/apk/release/ ``` Package with script + patched files at: `~/tmp/xhs_lsposed_a16_fix/` **Cannot build on-device:** Termux clang 21.1.8 crashes on C++23 template code (aarch64 clang bug). Requires x86_64 desktop with NDK.