Skip to content

Fix Android indexAdd input validation - #788

Open
ZacharyZcR wants to merge 1 commit into
cactus-compute:mainfrom
ZacharyZcR:fix/android-index-add-validation
Open

Fix Android indexAdd input validation#788
ZacharyZcR wants to merge 1 commit into
cactus-compute:mainfrom
ZacharyZcR:fix/android-index-add-validation

Conversation

@ZacharyZcR

Copy link
Copy Markdown

Closes #781.

Summary

  • reject mismatched ids, documents, embeddings, and metadatas before JNI
  • reject embedding rows with inconsistent dimensions
  • convert null embedding rows into promise rejections instead of uncaught exceptions

The validation and error messages match the existing iOS behavior.

Validation

  • git diff --check
  • manually verified each invalid path returns before nativeIndexAdd

The repository does not include a standalone React Native Android Gradle test project, so no Android compilation was run.

Signed-off-by: ZacharyZcR <zacharyzcr1984@gmail.com>
Copilot AI lite review requested due to automatic review settings August 14, 2026 02:11

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.

Pull request overview

This PR aligns the React Native Android indexAdd input validation behavior with iOS to prevent unsafe JNI calls when the JS inputs are malformed (e.g., mismatched array lengths or ragged embeddings).

Changes:

  • Reject indexAdd calls when ids, documents, embeddings, and optional metadatas lengths don’t match (before calling JNI).
  • Reject embeddings with inconsistent row dimensions to avoid out-of-bounds reads downstream.
  • Wrap readableNestedFloatArrays() so null embedding rows become promise rejections instead of uncaught exceptions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

val embArray = readableNestedFloatArrays(embeddings)
val embArray = try {
readableNestedFloatArrays(embeddings)
} catch (error: IllegalArgumentException) {
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.

RN Android indexAdd skips the input validation iOS performs — ragged embeddings cause an out-of-bounds read

2 participants