Repository navigation
Conversation
Fixes UndefinedBehaviorSanitizer report (STID 8146-795a) reproduced under
`Stress test (experimental, serverfuzz, arm_ubsan)`:
runtime error: nan is outside the range of representable values of type 'signed char'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
contrib/usearch/include/usearch/index_plugins.hpp:1216:42
`unum::usearch::cast_to_i8_gt::try_` is undefined behavior for two classes
of input:
- any non-finite element (NaN or +/-Inf): the cast
`static_cast<std::int8_t>(NaN)` is UB.
- a zero-magnitude vector with `i8` quantization: USearch normalizes by
the magnitude before quantizing, so the per-element ratio is NaN, then
casts to int8 (UB).
Both cases also produce silent garbage in non-sanitizer builds (USearch
indexes / searches with implementation-defined int8 values). They are
nonsensical at the user-facing level, so we reject them at the boundary.
The new helper `validateVectorElementsForUSearchOrThrow` is called both
from `MergeTreeIndexConditionVectorSimilarity::calculateApproximateNearestNeighbors`
(rejects bad reference vectors with `INCORRECT_QUERY`) and from the
per-row `add_vector_to_index` lambda inside `updateImpl` (rejects bad
indexed vectors with `INCORRECT_DATA`). NaN/Inf is rejected for every
quantization; zero-magnitude is rejected only for `i8`, since other
quantizations don't divide by the magnitude.
Adds regression test `04202_vector_search_i8_quantization_validation`
covering NaN, +Inf, -Inf, and zero-magnitude inputs on both `i8` and the
default (`bf16`) quantization, exercising both the SELECT and INSERT paths.
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=4aa433a573ba3177b4a879a0e24d689601728c60&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_ubsan%29
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Workflow [PR], commit [c4db417] Summary: ✅ AI ReviewSummaryThe PR adds input validation for vector similarity indexes to reject non-finite elements ( ClickHouse Rules
Final Verdict
|
LLVM Coverage Report
Changed lines: 94.44% (34/36) · Uncovered code |
|
Hi — could this be a backport candidate for Affected code: MergeTreeIndexVectorSimilarity::updateImpl and calculateApproximateNearestNeighbors — core code present in all supported branches. Why this might apply: The vector_similarity index and the affected code paths (updateImpl, calculateApproximateNearestNeighbors) exist in 25.8 branch. The UB being fixed can cause silent data corruption in non-sanitizer builds when users insert NaN/Inf values or zero-magnitude vectors with i8 quantization. Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reject non-finite vectors (nan, +-inf) during vector search, e.g. as searched vectors or as reference vectors. These cause undefined behavior in usearch.
Documentation entry for user-facing changes
Version info
26.5.1.474