From ad460db7eb21cbcdd4f509653f86acbcf43029dc Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 8 Jan 2025 15:54:44 +0000 Subject: [PATCH] Fix a crash in fts5 that could occur if shadow tables are modified or removed. FossilOrigin-Name: c0b691095ae72fc07530777ef6d23688fb4196ce2e0feff14fc3c597c572252d --- ext/fts5/fts5_index.c | 6 +- ext/fts5/fts5_storage.c | 5 + ext/fts5/test/fts5circref.test | 2 +- ext/fts5/test/fts5corrupt3.test | 233 +++++++++++++++++++++++++++++++ ext/fts5/test/fts5savepoint.test | 2 +- manifest | 22 +-- manifest.uuid | 2 +- 7 files changed, 257 insertions(+), 15 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 242258af70..2e512fd215 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -891,9 +891,13 @@ static int fts5IndexPrepareStmt( ){ if( p->rc==SQLITE_OK ){ if( zSql ){ - p->rc = sqlite3_prepare_v3(p->pConfig->db, zSql, -1, + int rc = sqlite3_prepare_v3(p->pConfig->db, zSql, -1, SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB, ppStmt, 0); + /* If this prepare() call fails with SQLITE_ERROR, then one of the + ** %_idx or %_data tables has been removed or modified. Call this + ** corruption. */ + p->rc = (rc==SQLITE_ERROR ? SQLITE_CORRUPT : rc); }else{ p->rc = SQLITE_NOMEM; } diff --git a/ext/fts5/fts5_storage.c b/ext/fts5/fts5_storage.c index 31f5fc5dc3..2b43016bef 100644 --- a/ext/fts5/fts5_storage.c +++ b/ext/fts5/fts5_storage.c @@ -205,6 +205,11 @@ static int fts5StorageGetStmt( if( rc!=SQLITE_OK && pzErrMsg ){ *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db)); } + if( rc==SQLITE_ERROR && eStmt>FTS5_STMT_LOOKUP2 && eStmt