A16 JNINativeInterface Crash — Root Cause & Fix
Symptom
LSPosed (official v1.9.2 AND JingMatrix/Vector v2.0) crashes zygote64 on Android 16:
JNI DETECTED ERROR IN APPLICATION: negative buffer capacity in NewDirectByteBuffer
from int com.android.internal.os.Zygote.nativeForkSystemServer
Magisk detects repeated zygote crashes → auto-rolls-back Zygisk. Modules never inject.
Root Cause
zygisk/src/main/cpp/ipc_bridge.cpp line 557:
memcpy(&native_interface_hook_, env->functions, sizeof(JNINativeInterface));
sizeof(JNINativeInterface) is a compile-time constant (~2376 bytes with NDK 26).
Android 16 ART added new JNI functions, expanding the runtime structure.
The memcpy truncates — new function pointers become garbage.
ART later calls them → crash (negative buffer capacity).
The reserved0 field stores the actual runtime size (ART sets it),
so SetTableOverride sees the correct size and treats garbage as valid pointers.
Fix
Replace compile-time sizeof with runtime reserved0:
ipc_bridge.h:167 — change from stack allocation to pointer:
JNINativeInterface* native_interface_hook_ = nullptr;
size_t table_size_ = 0;
ipc_bridge.cpp:555-566 — dynamic allocation:
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_);
Build & Deploy
git clone --depth 1 --recursive https://github.com/JingMatrix/LSPosed.git
bash apply_a16_fix.sh .
export ANDROID_HOME=/path/to/sdk
./gradlew :zygisk:assembleRelease
# Output .so replaces: /data/adb/modules/zygisk_vector/zygisk/arm64-v8a.so
Full fix package (script + patched sources + README):
~/tmp/xhs_lsposed_a16_fix/ on device, also sent to Feishu contact "bo".
Verification After Deploy
su -c 'pidof lspd'
su -c 'cat /proc/$(pidof zygote64)/maps | grep zygisk'
su -c 'cat /proc/$(pidof com.xingin.xhs)/maps | grep xhshook'