Repository navigation
fix: validate C enum inputs at the FFI boundary - #86
Merged
Merged
Conversation
Take the existing C enum parameters and the vector index config field as c_int in Rust, validate them before constructing Rust enums, and keep the public header and established error conventions unchanged. Add C consumer regression tests for out-of-range index, distance, optimize and binary-op values. The helper is compiled as C17 against the public header.
C_STANDARD on a source file is ignored by CMake. Set C_STANDARD, C_STANDARD_REQUIRED and C_EXTENSIONS on the three targets that compile the C consumer helper, leaving their C++ sources and all other targets unchanged.
…idation # Conflicts: # tests/test_index.cpp
Stop scheduling the removed macos-15-intel packaging job. The standalone C packaging change will remove the remaining script and documentation references.
Xuanwo
added a commit
that referenced
this pull request
Nov 21, 2026
Reuse the checked enum conversions added by #86: LanceDBIndexType::from_c_int for the create index type and LanceDBDistanceType::from_c_int behind the optional -1 distance marker. Add a C17 helper for lancedb_table_create_index so the out-of-range index value stays an ordinary C integer, then assert the call is rejected and leaves the index list empty. The other generic-create and index-list cases are unchanged.
This was referenced Nov 21, 2026
Xuanwo
added a commit
that referenced
this pull request
Nov 21, 2026
* index: create indexes with names, waits and tuning options Add lancedb_table_create_index, a single additive entry point that covers the SDK's common index creation options and the per-type tuning required by the published and current Go index APIs. The new LanceDBIndexOptions keeps omission distinct from explicit values: numeric fields use -1 for unset, boolean fields use -1 for unset and 0/1 for false/true, and strings use NULL for unset. This lets callers leave one FTS flag at the SDK default while explicitly setting another to false, which the existing per-type config structs cannot express. Numeric parameters are carried as int64 so every uint32 value and the -1 sentinel fit without truncation. The entry point also exposes the SDK index name, replace choice and builder-level wait_timeout. The wait is a polling budget, not a wall-clock bound, and native tables ignore it. LANCEDB_INDEX_AUTO remains the SDK Auto index rather than the Go Auto-to-IVF-PQ mapping. Raw index and distance enums are validated before conversion. Invalid ranges, invalid UTF-8, unsupported index types and SDK errors are returned with their messages. Existing create signatures, defaults and Go code are unchanged. Consumer tests cover a name distinct from the column, explicit replace false versus true, FTS and ngram options, vector IVF/PQ/HNSW tuning, cosine versus L2 changing a real query result, and invalid input ranges. * test: make index metric regression deterministic Replace the nearly collinear 256-row fixture with four controlled vectors whose L2 and cosine winners are far apart. Query without setting a metric, so the SDK uses the metric of the built index. The cosine case fails and returns row_0 if the creation option is dropped. Also document the actual remote create wait: servers that return a job ID use the SDK timeout on that job, legacy servers fall back to polling the named index, and reaching the budget does not cancel the submitted build. Native tables remain synchronous and ignore the option. * ci: drop retired Intel macOS package job * test: drop out-of-range C++ index enum cast * docs: describe actual SDK create wait behavior * docs: remove redundant create wait sentence * test: cover generic index creation options * test: cover generic create invalid index enum Reuse the checked enum conversions added by #86: LanceDBIndexType::from_c_int for the create index type and LanceDBDistanceType::from_c_int behind the optional -1 distance marker. Add a C17 helper for lancedb_table_create_index so the out-of-range index value stays an ordinary C integer, then assert the call is rejected and leaves the index list empty. The other generic-create and index-list cases are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Take the existing C enum inputs as
c_intat the Rust FFI boundary and validate them withfrom_c_intbefore constructing Rust enums. This removes undefined behavior when a C caller passes a value outside the public header's enumerators.Covered inputs:
lancedb_table_create_vector_indexandlancedb_table_create_scalar_indexindex_typeLanceDBVectorIndexConfig.distance_typelancedb_table_optimizeoptimize_typelancedb_vector_query_distance_typedistance_typelancedb_expr_binaryopThe public C header layout and signatures are unchanged. Invalid values keep the existing error conventions:
LANCEDB_INVALID_ARGUMENTwhere an error code is returned, andNULLforlancedb_expr_binary.The change also adds C consumer regression tests that pass out-of-range values through the public C ABI, plus compile-time checks that the C enums and
LanceDBVectorIndexConfigkeep the ABI the Rust layer expects. The helper is compiled as C17.Addresses the existing-main FFI inputs described in #75. No changes to #74.
Validation
cargo check --libcargo clippy --libBUILD_EXAMPLES=ON,BUILD_TESTS=ON,CMAKE_BUILD_TYPE=Releaseninja -C build -j 12ctest --test-dir build -j 4: all 9 test suites passed, including the valgrind-backed index and DataFusion expression suiteslancedb_index_tests,lancedb_vector_query_tests, andlancedb_df_query_tests-Werrorcompile of the C consumer helper