]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
If SQLITE_DEBUG is defined, fts5 does extra checks as part of integrity-check. Ensure...
authordan <Dan Kennedy>
Tue, 8 Jul 2025 14:54:20 +0000 (14:54 +0000)
committerdan <Dan Kennedy>
Tue, 8 Jul 2025 14:54:20 +0000 (14:54 +0000)
FossilOrigin-Name: 98a53fb276fa1fa733da2dd3255c35ce9f6af9b9feef6e76fb577b6d142167a2

ext/fts5/fts5_index.c
manifest
manifest.uuid

index 5a5063748693eb13f91e4e210da2e90b2f30c496..7526330644d6dea91081f21d417b989bbd756e44 100644 (file)
@@ -8286,14 +8286,19 @@ static int fts5TestUtf8(const char *z, int n){
 /*
 ** This function is also purely an internal test. It does not contribute to 
 ** FTS functionality, or even the integrity-check, in any way.
+**
+** This function sets output variable (*pbFail) to true if the test fails. Or
+** leaves it unchanged if the test succeeds.
 */
 static void fts5TestTerm(
   Fts5Index *p, 
   Fts5Buffer *pPrev,              /* Previous term */
   const char *z, int n,           /* Possibly new term to test */
   u64 expected,
-  u64 *pCksum
+  u64 *pCksum,
+  int *pbFail
 ){
+  int bRet = 0;
   int rc = p->rc;
   if( pPrev->n==0 ){
     fts5BufferSet(&rc, pPrev, n, (const u8*)z);
@@ -8348,7 +8353,7 @@ static void fts5TestTerm(
     fts5BufferSet(&rc, pPrev, n, (const u8*)z);
 
     if( rc==SQLITE_OK && cksum3!=expected ){
-      rc = FTS5_CORRUPT;
+      *pbFail = 1;
     }
     *pCksum = cksum3;
   }
@@ -8357,7 +8362,7 @@ static void fts5TestTerm(
  
 #else
 # define fts5TestDlidxReverse(x,y,z)
-# define fts5TestTerm(u,v,w,x,y,z)
+# define fts5TestTerm(t,u,v,w,x,y,z)
 #endif
 
 /*
@@ -8615,6 +8620,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
   /* Used by extra internal tests only run if NDEBUG is not defined */
   u64 cksum3 = 0;                 /* Checksum based on contents of indexes */
   Fts5Buffer term = {0,0,0};      /* Buffer used to hold most recent term */
+  int bTestFail = 0;
 #endif
   const int flags = FTS5INDEX_QUERY_NOOUTPUT;
   
@@ -8657,7 +8663,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
     char *z = (char*)fts5MultiIterTerm(pIter, &n);
 
     /* If this is a new term, query for it. Update cksum3 with the results. */
-    fts5TestTerm(p, &term, z, n, cksum2, &cksum3);
+    fts5TestTerm(p, &term, z, n, cksum2, &cksum3, &bTestFail);
     if( p->rc ) break;
 
     if( eDetail==FTS5_DETAIL_NONE ){
@@ -8675,7 +8681,7 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
       }
     }
   }
-  fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3);
+  fts5TestTerm(p, &term, 0, 0, cksum2, &cksum3, &bTestFail);
 
   fts5MultiIterFree(pIter);
   if( p->rc==SQLITE_OK && bUseCksum && cksum!=cksum2 ){
@@ -8684,11 +8690,17 @@ int sqlite3Fts5IndexIntegrityCheck(Fts5Index *p, u64 cksum, int bUseCksum){
         "fts5: checksum mismatch for table \"%s\"", p->pConfig->zName
     );
   }
-
-  fts5StructureRelease(pStruct);
 #ifdef SQLITE_DEBUG
+  /* In SQLITE_DEBUG builds, expensive extra checks were run as part of
+  ** the integrity-check above. If no other errors were detected, but one
+  ** of these tests failed, set the result to SQLITE_CORRUPT_VTAB here. */
+  if( p->rc==SQLITE_OK && bTestFail ){
+    p->rc = FTS5_CORRUPT;
+  }
   fts5BufferFree(&term);
 #endif
+
+  fts5StructureRelease(pStruct);
   fts5BufferFree(&poslist);
   return fts5IndexReturn(p);
 }
index 8849616fcc95ac4a6661f3dd8ad3cd56ced22b8d..047bd78443a7f134f54502e85f3971edc63a8d1f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\stest\scase\sresults\sin\sFTS5\sthat\swere\schanged\serror\smessage\simprovements\nin\s[48044a6b57c0a16c]\sbut\swhich\swere\somitted\sfrom\sthat\scheck-in.
-D 2025-07-08T12:37:25.996
+C If\sSQLITE_DEBUG\sis\sdefined,\sfts5\sdoes\sextra\schecks\sas\spart\sof\sintegrity-check.\sEnsure\sthat\serrors\sfrom\sthese\sextra\schecks\sare\sonly\sreported\sif\sthe\sother,\snormal,\stests\sall\spass.\sThis\sfixes\sa\stest\scase\sin\sfts5corrupt3.test\sthat\swas\sfailing\sif\sSQLITE_DEBUG\swas\sdefined.
+D 2025-07-08T14:54:20.049
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -113,7 +113,7 @@ F ext/fts5/fts5_buffer.c f1e6d0324d7c55329d340673befc26681a372a4d36086caa8d1ec7d
 F ext/fts5/fts5_config.c e7d8dd062b44a66cd77e5a0f74f23a2354cd1f3f8575afb967b2773c3384f7f8
 F ext/fts5/fts5_expr.c be9e5f7f11d87e7bd3680832c93c13050fe351994b5052b0215c2ef40312c23a
 F ext/fts5/fts5_hash.c a6266cedd801ab7964fa9e74ebcdda6d30ec6a96107fa24148ec6b7b5b80f6e0
-F ext/fts5/fts5_index.c ed562b75c87efaa80c40e55f6c1102904728e35baa293c371f96b1c8e151399d
+F ext/fts5/fts5_index.c aa1da5db8383da13a620312b60cdb997ec265cd2fa4e9a2e6cea8f864c42c279
 F ext/fts5/fts5_main.c e558225168845dc708abeb2ad10415696e5a3249bcba1810ba3c7ef80764962e
 F ext/fts5/fts5_storage.c 19bc7c4cbe1e6a2dd9849ef7d84b5ca1fcbf194cefc3e386b901e00e08bf05c2
 F ext/fts5/fts5_tcl.c 7fb5a3d3404099075aaa2457307cb459bbc257c0de3dbd52b1e80a5b503e0329
@@ -2208,8 +2208,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 56314b6b53c86ae131f780e20b62bdeabccba6d62dda41becc1c4b2e87cee07b
-R dc894f7a0ca88716616acdb5c2fedf44
-U drh
-Z a929e93c97a2220333e660f05941e298
+P e1f8e0240b14f1338e947634e840af785e5042a09cd365975e922a13a562f4cd
+R 2fa6dffea449b33b5ab95a81c97744b0
+U dan
+Z a3e485555db3d8ba12554cbb5df06f32
 # Remove this line to create a well-formed Fossil manifest.
index e92173e7f5af9c8a2c42d2b16062ae3b8941aa59..e54c57f7b339dd3bcecaf92ffc04097d7b14fe11 100644 (file)
@@ -1 +1 @@
-e1f8e0240b14f1338e947634e840af785e5042a09cd365975e922a13a562f4cd
+98a53fb276fa1fa733da2dd3255c35ce9f6af9b9feef6e76fb577b6d142167a2