Skip to content

fix: validate and raise ValueError for negative n in get_nns methods - #701

Open
saitejabandaru-in wants to merge 1 commit into
spotify:mainfrom
saitejabandaru-in:fix/integer-overflow-negative-n
Open

fix: validate and raise ValueError for negative n in get_nns methods#701
saitejabandaru-in wants to merge 1 commit into
spotify:mainfrom
saitejabandaru-in:fix/integer-overflow-negative-n

Conversation

@saitejabandaru-in

Copy link
Copy Markdown

Fixes #700. When passing a negative number for n (number of neighbors) to get_nns_by_item or get_nns_by_vector, the signed int32_t parses correctly but is cast to unsigned size_t inside get_nns_by_item in the C++ library. This causes it to become SIZE_MAX, leading to integer overflows in search_k and returning meaningless values or empty lists. This adds a clean check in the Python C-extension wrapper to raise a ValueError.

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.

[Bug] Passing a negative number for 'n' to 'get_nns_by_item' or 'get_nns_by_vector' causes incorrect results and integer overflow

1 participant