Repository navigation
fix(utils)!: remove the evaluation helpers from tools.hpp - #262
Merged
Merged
Conversation
distance_ratio and horizontal_avg in the installed header rabitqlib/utils/tools.hpp had undefined behavior. distance_ratio formed data + id * dim for every result ID, so a missing result (kNoId or kPidMax, which the index searches use for padding) read out of bounds. horizontal_avg read data[0] on empty input, read past shorter rows, and divided signed sums by a size_t, so horizontal_avg<int> of three rows of -1 gave 1431655764. Neither is index functionality: distance_ratio has no callers, and horizontal_avg's only callers are the C++ querying samples. Remove both, and the <cmath>, <queue> and <vector> includes only they used. The samples average their measurements with querying_example::column_averages in sample/cpp/querying_example.hpp. The release notes record the removal.
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.
rabitqlib/utils/tools.hppis an installed header, and two evaluation helpers in it had undefined behavior:distance_ratioformeddata + id * dimfor every result ID without a check, so a missing result (kNoIdfromIvfIndex/HnswIndex/SymqgIndex, orkPidMaxfrom the lower-level searches) read out of bounds (ASan: heap-buffer-overflow).horizontal_avgreaddata[0]on empty input, read past shorter rows, and divided signed sums by asize_t:horizontal_avg<int>of three rows of -1 returned 1431655764.Neither is index functionality.
distance_ratiohas no callers, andhorizontal_avg's only callers are the three C++ querying samples, so this removes both instead of fixing them. A safedistance_ratiowould also need a point-count parameter, which changes its signature anyway.Change
distance_ratioandhorizontal_avgfromtools.hpp, with the<cmath>,<queue>and<vector>includes only they used.querying_example::column_averagesin the newsample/cpp/querying_example.hpp. On the samples' rectangularfloatmatrices it gives the same results as before, bit for bit.std::priority_queuemust include<queue>.<vector>and<cmath>still come through other headers.Compatibility
Code calling
rabitqlib::distance_ratioorrabitqlib::horizontal_avgno longer compiles; 0.9 is a breaking release. zvec, the known C++ downstream, uses neither and does not usestd::priority_queuethrough RaBitQ headers (checked by code search and a clone of its default branch).Checks run (Linux x86-64, native optimization off)
tests/core_consumer/run.cmakewith OpenMP off.check-includes.sh: the same diagnostics as the base.check-format.sh, fullcheck-tidy.sh,mkdocs build --strict,git diff --check.There are no new tests: removing the helpers leaves no behavior to test, and the sample helper is covered by building the samples.