Fix potential OOB access in CAGRA search when graph size < dataset size#1780
Open
irina-resh-nvda wants to merge 16 commits intorapidsai:mainfrom
Open
Fix potential OOB access in CAGRA search when graph size < dataset size#1780irina-resh-nvda wants to merge 16 commits intorapidsai:mainfrom
irina-resh-nvda wants to merge 16 commits intorapidsai:mainfrom
Conversation
…rs to constrain random seed node selection to a subset of the dataset. This is useful when the graph is smaller than the dataset, such as during iterative build with compression.
…oved max_node_id from the search parameters structure
mfoerste4
approved these changes
Feb 10, 2026
Contributor
mfoerste4
left a comment
There was a problem hiding this comment.
LGTM, only minor suggestions.
| uint32_t* const num_executed_iterations, /* stats */ | ||
| SAMPLE_FILTER_T sample_filter) | ||
| SAMPLE_FILTER_T sample_filter, | ||
| const typename DATASET_DESCRIPTOR_T::INDEX_T graph_size = 0) |
Contributor
There was a problem hiding this comment.
Is the default value used anywhere besides tests?
Contributor
Author
There was a problem hiding this comment.
the default is used everywhere but the tests and thefuture iterative cagra q implementation
cpp/src/neighbors/detail/cagra/search_single_cta_kernel-inl.cuh
Outdated
Show resolved
Hide resolved
tfeher
approved these changes
Mar 3, 2026
Contributor
tfeher
left a comment
There was a problem hiding this comment.
Thanks Irina, the PR looks good to me.
cpp/tests/neighbors/ann_cagra/bug_graph_smaller_than_dataset.cu
Outdated
Show resolved
Hide resolved
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.
Random seed node selection incorrectly used
dataset_desc.sizeto generate indices. Whengraph.extent(0) < dataset.size, this caused OOB access by attempting to index graph rows that don't exist.This PR fixes an out-of-bounds memory access bug in CAGRA search that occurs when the graph has fewer nodes than the dataset (e.g., during iterative CAGRA-Q builds with compression).
Solution
Thread
graph.extent(0)through the search kernel call chain as agraph_sizeparameter. Random seeds are now correctly constrained to[0, graph.extent(0))instead of[0, dataset.size).Purely internal fix with no API changes. Existing behavior unchanged for normal CAGRA usage where graph and dataset sizes match.
Testing
Added test that builds an index on 5,000 points, expands the dataset to 10,000 points via
update_dataset(), then runs search. This reproduces the exact scenario where the bug would occur. Test verifies both SINGLE_CTA and MULTI_CTA algorithms complete without OOB access.