Skip to content

bindings: JNI & React-Native FFI memory-safety - #708

Merged
jakmro merged 1 commit into
mainfrom
audit/bindings-ffi-safety
Jun 12, 2026
Merged

jakmro merged 1 commit into
mainfrom
audit/bindings-ffi-safety

Conversation

@ncylich

@ncylich ncylich commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

cactus_jni.cpp: clear pending Java exceptions after callback dispatch, reserve local-ref capacity for batched index_add, and clean up partially-acquired refs on null array elements. Cactus.swift: validate equal lengths and uniform embedding-row widths before calling native index_add to prevent out-of-bounds reads.

Signed-off-by: Noah Cylich noahcylich@gmail.com

ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
Comment thread android/cactus_jni.cpp Resolved
@kar-m

kar-m commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

even with the issue in comment i think this lgtm @jakmro
I tested and the original bug reproduces and this doesnt create regressions as far as i could test. Don't have a android device to test directly though
EDIT: Noah pushed change fixing, now LGTM

ncylich added a commit that referenced this pull request Jun 10, 2026
In nativeIndexAdd, IndexAddBuffers and QueryResults, EnsureLocalCapacity's return value was ignored; on failure it leaves a pending OutOfMemoryError, so the subsequent JNI calls would run with a pending exception. Gate element acquisition on a successful EnsureLocalCapacity instead — on failure the loop is skipped and the existing acquired<count path clears the exception and returns -1. Addresses review feedback on #708.

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
cactus_jni.cpp: clear pending Java exceptions after token/log callback dispatch so the next native->Java transition doesn't run with one pending; on batched index_add/query, handle null array elements by releasing the partially-acquired refs (tracked via 'acquired') and bailing instead of dereferencing null. Cactus.swift: validate equal ids/documents/embeddings/metadatas lengths and uniform embedding-row widths before calling native index_add to prevent out-of-bounds reads.

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
@ncylich
ncylich force-pushed the audit/bindings-ffi-safety branch from 8a0f33f to 6100a55 Compare June 10, 2026 02:51
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich added a commit that referenced this pull request Jun 10, 2026
…ot for direct merge)

Signed-off-by: Noah Cylich <noahcylich@gmail.com>
@ncylich
ncylich marked this pull request as ready for review June 10, 2026 06:05
Copilot AI review requested due to automatic review settings June 10, 2026 06:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jakmro
jakmro merged commit 6d0c441 into main Jun 12, 2026
7 of 8 checks passed
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.

4 participants