fix(index): reject out-of-range partition ids when computing residuals - #9004
Open
LuciferYang wants to merge 1 commit into
Open
fix(index): reject out-of-range partition ids when computing residuals#9004LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
compute_residual indexes the centroid buffer with the partition id straight from the batch. Partition ids normally come from the transformer that just assigned them, but a precomputed_partition_dataset supplies them as user data and nothing range-checks it, so an id beyond the centroid count panicked on the slice. Return invalid_input naming the id and the centroid count instead.
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The guard is at the centroid slice boundary that previously panicked, uses the actual centroid count, and preserves valid residual computation. Regression coverage exercises both the direct residual path and a full IVF_PQ build with a precomputed partition dataset.
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.
Problem
do_compute_residualindexes the centroid buffer with the partition id straight from the batch. Ids assigned by the transformer are in range by construction, but aprecomputed_partition_datasetsupplies them as user data and nothing range-checks it before the slice, so an id beyond the centroid count panicked.Fixes #9003.
What this changes
Return
invalid_inputnaming the id and the centroid count instead of slicing.The shuffler already does this for its own per-partition buffers (
v3/shuffler.rs:600-606), but the transform chain runs before the shuffle, so for IVF_PQ the residual slice is what the id reaches first.Test plan
test_compute_residual_rejects_out_of_range_partitionpasses id 5 against two centroids and asserts the variant and both numbers in the message. Without the check it panics withrange start index 10 out of range for slice of length 4.test_create_ivf_pq_rejects_out_of_range_precomputed_partitionbuilds a real IVF_PQ index from a partitions dataset that assigns one row to partition 7 out of 2, and asserts the error rather than a panic.cargo test -p lance-index --lib1231 passed, 3 ignoredcargo test -p lance --lib index::vector::ivf::tests::passedcargo clippy --all --tests --benches -- -D warningscleancargo fmt --all --checkcleanNot in this change
IvfShuffler, the legacy shuffler behindLANCE_LEGACY_SHUFFLER=1, indexes its partition buffers without a range check (v3/shuffler.rs:261) and would still panic on the same input. The defaultTwoFileShufflerpath is the one that checks.