Repository navigation
libsql-sqlite3: Fix vector_top_k crash with k = 0 - #2332
Open
colinhacks wants to merge 1 commit into
Open
colinhacks wants to merge 1 commit into
colinhacks wants to merge 1 commit into
Conversation
diskAnnSearch passed k as the size of the top-candidates buffers, so k = 0 made sqlite3_malloc(0) return NULL. The init then freed its buffers and returned SQLITE_NOMEM, and the error path freed them again. Return no rows for k = 0 up front, and return straight after a failed init. Also return the arguments for the hidden idx, vector and k columns, which read the output rows with a negative column index before.
This branch has not been deployed
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.
vector_top_kwithk= 0 on an index that has rows crashed the process with a double free.diskAnnSearchpassedkas the size of the top-candidates buffers, sosqlite3_malloc(0)returned NULL.diskAnnSearchCtxInitthen freed the buffers it did get, deinitialized the query vectors and returnedSQLITE_NOMEM, and theout:path indiskAnnSearchfreed all of it again.diskAnnSearchreturns no rows fork= 0 before the init, the same way it does for an empty index.diskAnnSearchCtxDeinit, asdiskAnnInsertalready does.idx,vectorandkcolumns return the arguments the query passed.vectorVtabColumnread the output rows atiCol - 3for them, a negative index, so all three came back as the row'sid.The bundled amalgamations in
libsql-ffi/bundled(plain and SQLite3MultipleCiphers) are regenerated from the patched source, so the diff there is the same hunks.Testing
Added
vector-top-k-zeroandvector-hidden-columnstotest/libsql_vector_index.test. Without the change testfixture aborts at the first one, and the query in the second returns theidin all four columns. With it both pass, along with the rest oflibsql_vector_index.test.libsql_vector.testpasses exceptvector-1-conversion-f8, which fails the same way without the change (a float rounding difference, built on macOS arm64). I didn't run the Rust crates' tests.The
ktruncation from the issue isn't covered here.Fixes #2331