From 44e4438ed54bb1cf2bf79eee7f44093e12dca74b Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 10 Jan 2025 14:44:37 -0800 Subject: [PATCH] fix segfault on invalid vec_each() input, fixes #163 --- sqlite-vec.c | 4 +++- tests/test-loadable.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sqlite-vec.c b/sqlite-vec.c index d8490cd..3cc802f 100644 --- a/sqlite-vec.c +++ b/sqlite-vec.c @@ -2483,7 +2483,9 @@ static int vec_eachOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor) { static int vec_eachClose(sqlite3_vtab_cursor *cur) { vec_each_cursor *pCur = (vec_each_cursor *)cur; - pCur->cleanup(pCur->vector); + if(pCur->vector) { + pCur->cleanup(pCur->vector); + } sqlite3_free(pCur); return SQLITE_OK; } diff --git a/tests/test-loadable.py b/tests/test-loadable.py index b14902a..a8058c9 100644 --- a/tests/test-loadable.py +++ b/tests/test-loadable.py @@ -1614,6 +1614,9 @@ def test_vec_each(): {"rowid": 2, "value": 3.0}, ] + with _raises("Input must have type BLOB (compact format) or TEXT (JSON), found NULL"): + vec_each_f32(None) + import io