Fix overflow in VecSimParams_GetQueryBlobSize#968
Closed
dor-forer wants to merge 1 commit into
Closed
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
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.
Motivation
VecSimParams_GetQueryBlobSizecomputedVecSimType_sizeof(type) * dimand addedsizeof(float)for INT8/UINT8 cosine without checking forsize_toverflow, which can wrap and cause undersized allocations and subsequent out-of-bounds accesses.Description
VecSimParams_GetQueryBlobSizeby checkingelement_size > SIZE_MAX / dimbefore multiplication andblobSize > SIZE_MAX - sizeof(float)before the cosine norm addition, returning0if the required size cannot be represented insize_t.dimvalues.TestGetQueryBlobSizeOverflowintests/unit/test_common.cppthat assertsVecSimParams_GetQueryBlobSizereturns0for a multiplication overflow dimension and for the addition overflow case for INT8/UINT8 cosine.src/VecSim/vec_sim.cppandtests/unit/test_common.cpp.Testing
TestGetQueryBlobSizeOverflowbut could not execute the test suite in this environment because CMakeFetchContentdownloads from GitHub are blocked (HTTP 403) and configuring/building tests failed.cmake -S . -B build -DCMAKE_BUILD_TYPE=Release, which failed due to an SVS dependency download returning HTTP 403.-DUSE_SVS=OFF -DVECSIM_BUILD_TESTS=ONbut the build still failed becausegoogletestdownload was blocked with HTTP 403; no unit tests were run here as a result.Codex Task