Recently we introduced new idxType = 4 in the native SQLite code which corresponds to the vector index.
Internally, SQLite use this field in several places and we tried to make SQLite believe that idxType = 4 is equivalent to idxType = 0 (which is APPDEF user defined-index). We missed one spot which results in the out-of-bound read and SEGFAULT in some cases (for some reason, SEGFAULT reproduced stably on Mac but code works fine on Linux with this bug :thinking: ).
This PR fixes SEGFAULT for PRAGMA index_list='...' statements and also change our approach: instead of introducing new idxType we add new field idxIsVector which we will use to distinguish ordinary indices from the vector one but sqlite code will see our vector indices as APPDEF indices. This is more robust change because it will work for future SQLite changes more smoothly and will require less patches from our side.
Originally, this issue were found while testing vector feature with cr-sqlite extension which uses PRAGMA index_list='...' under the hood to analyze table/index structure. Example of stacktrace for SELECT crsql_as_crr('...') call resulting in the SEGFAULT:
Context
Recently we introduced new
idxType = 4
in the native SQLite code which corresponds to the vector index.Internally, SQLite use this field in several places and we tried to make SQLite believe that
idxType = 4
is equivalent toidxType = 0
(which is APPDEF user defined-index). We missed one spot which results in the out-of-bound read andSEGFAULT
in some cases (for some reason,SEGFAULT
reproduced stably on Mac but code works fine on Linux with this bug :thinking: ).This PR fixes
SEGFAULT
forPRAGMA index_list='...'
statements and also change our approach: instead of introducing newidxType
we add new fieldidxIsVector
which we will use to distinguish ordinary indices from the vector one but sqlite code will see our vector indices asAPPDEF
indices. This is more robust change because it will work for future SQLite changes more smoothly and will require less patches from our side.Failing piece of code in the
PRAGMA
implementation: https://github.com/tursodatabase/libsql/blob/8262d238f5fad9b6ecbc1e27a82b781d602e63b8/libsql-sqlite3/src/pragma.c#L1390-L1398Originally, this issue were found while testing vector feature with cr-sqlite extension which uses
PRAGMA index_list='...'
under the hood to analyze table/index structure. Example of stacktrace forSELECT crsql_as_crr('...')
call resulting in theSEGFAULT
: