Skip to content

Commit 1b53b94

Browse files
asg017claude
andcommitted
Fix remaining fuzzer issues: leaks, UBSAN NaN, macOS LLVM version
- fuzz.yaml: switch macOS to llvm@18 (latest LLVM uses typed allocation C++ ABI symbols not available on macOS 14 runner's system libc++) - sqlite-vec.c: fix NaN input in vec_quantize_int8 by using !(val <= X) comparisons which evaluate to true for NaN, ensuring the clamp fires - sqlite-vec.c: free pzErrMsg in vec_eachFilter error path (was leaking the error string returned by vector_from_value) - sqlite-vec.c: add sqlite3_free(pNew) to vec0_init error path; vec0_free frees the contents but not the struct itself, mirroring vec0Disconnect - sqlite-vec.c: free knn_data in vec0Filter_knn cleanup when rc != SQLITE_OK; on error the cursor's knn_data field is never set so it would not be freed by the cursor teardown path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8c97620 commit 1b53b94

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

.github/workflows/fuzz.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ jobs:
6363
runs-on: macos-14
6464
steps:
6565
- uses: actions/checkout@v4
66-
- name: Install LLVM
67-
run: brew install llvm
66+
- name: Install LLVM 18
67+
run: brew install llvm@18
6868
- run: ./scripts/vendor.sh
6969
- name: Generate sqlite-vec.h
7070
run: make sqlite-vec.h
7171
- name: Build fuzz targets
7272
run: |
73-
LLVM=/opt/homebrew/opt/llvm
73+
LLVM=/opt/homebrew/opt/llvm@18
7474
make -C tests/fuzz all \
7575
FUZZ_CC=$LLVM/bin/clang \
76-
FUZZ_LDFLAGS="-Wl,-ld_classic -L$LLVM/lib/c++ -Wl,-rpath,$LLVM/lib/c++"
76+
FUZZ_LDFLAGS="-Wl,-ld_classic"
7777
- name: Run fuzz targets
7878
env:
79-
DYLD_LIBRARY_PATH: "/opt/homebrew/opt/llvm/lib/c++:${{ env.DYLD_LIBRARY_PATH }}"
79+
DYLD_LIBRARY_PATH: "/opt/homebrew/opt/llvm@18/lib/c++:${{ env.DYLD_LIBRARY_PATH }}"
8080
run: |
8181
DURATION=${{ github.event.inputs.duration || '60' }}
8282
EXIT_CODE=0

sqlite-vec.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,8 @@ static void vec_quantize_int8(sqlite3_context *context, int argc,
14651465
f32 step = (1.0 - (-1.0)) / 255;
14661466
for (size_t i = 0; i < dimensions; i++) {
14671467
double val = ((srcVector[i] - (-1.0)) / step) - 128;
1468-
if (val > 127.0) val = 127.0;
1469-
if (val < -128.0) val = -128.0;
1468+
if (!(val <= 127.0)) val = 127.0; /* also clamps NaN */
1469+
if (!(val >= -128.0)) val = -128.0;
14701470
out[i] = (i8)val;
14711471
}
14721472

@@ -2577,6 +2577,7 @@ static int vec_eachFilter(sqlite3_vtab_cursor *pVtabCursor, int idxNum,
25772577
int rc = vector_from_value(argv[0], &pCur->vector, &pCur->dimensions,
25782578
&pCur->vector_type, &pCur->cleanup, &pzErrMsg);
25792579
if (rc != SQLITE_OK) {
2580+
sqlite3_free(pzErrMsg);
25802581
return SQLITE_ERROR;
25812582
}
25822583
pCur->iRowid = 0;
@@ -5202,6 +5203,7 @@ static int vec0_init(sqlite3 *db, void *pAux, int argc, const char *const *argv,
52025203

52035204
error:
52045205
vec0_free(pNew);
5206+
sqlite3_free(pNew);
52055207
return SQLITE_ERROR;
52065208
}
52075209

@@ -7259,6 +7261,10 @@ int vec0Filter_knn(vec0_cursor *pCur, vec0_vtab *p, int idxNum,
72597261

72607262
sqlite3_free(aMetadataIn);
72617263

7264+
if (rc != SQLITE_OK) {
7265+
sqlite3_free(knn_data);
7266+
}
7267+
72627268
return rc;
72637269
}
72647270

0 commit comments

Comments
 (0)