]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Working when run against sqlite.fossil.
authordrh <drh@noemail.net>
Thu, 5 May 2016 23:39:30 +0000 (23:39 +0000)
committerdrh <drh@noemail.net>
Thu, 5 May 2016 23:39:30 +0000 (23:39 +0000)
FossilOrigin-Name: b0bd9dd6255be161ea289ba6caa3fbd568128f62

ext/misc/scrub.c
manifest
manifest.uuid

index 424db6baf58e7cfeeb7b4cdbc8b5a8679ed308c1..153625abed0b1f747c8d542a33caa6a20c167685 100644 (file)
@@ -342,7 +342,7 @@ static void scrubBackupOverflow(ScrubState *p, int pgno, u32 nByte){
   if( aBuf==0 ) return;
   while( nByte>0 && pgno!=0 ){
     a = scrubBackupRead(p, pgno, aBuf);
-    if( a ) break;
+    if( a==0 ) break;
     if( nByte >= (p->szUsable)-4 ){
       nByte -= (p->szUsable) - 4;
     }else{
@@ -372,6 +372,7 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
   u8 *aTop;
   u8 *aCell;
   u32 x, y;
+  int ln = 0;
 
   
   if( p->rcErr ) return;
@@ -394,21 +395,21 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
   /* Zero out the gap between the cell index and the start of the
   ** cell content area */
   x = scrubBackupInt16(&aTop[5]);  /* First byte of cell content area */
-  if( x>p->szUsable ) goto btree_corrupt;
+  if( x>p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
   y = szHdr + nPrefix + nCell*2;
-  if( y>x ) goto btree_corrupt;
+  if( y>x ){ ln=__LINE__; goto btree_corrupt; }
   if( y<x ) memset(a+y, 0, x-y);  /* Zero the gap */
 
   /* Zero out all the free blocks */  
   pc = scrubBackupInt16(&aTop[1]);
-  if( pc<x+4 ) goto btree_corrupt;
+  if( pc>0 && pc<x ){ ln=__LINE__; goto btree_corrupt; }
   while( pc ){
-    if( pc>(p->szUsable)-4 ) goto btree_corrupt;
+    if( pc>(p->szUsable)-4 ){ ln=__LINE__; goto btree_corrupt; }
     n = scrubBackupInt16(&a[pc+2]);
-    if( pc+n>(p->szUsable) ) goto btree_corrupt;
+    if( pc+n>(p->szUsable) ){ ln=__LINE__; goto btree_corrupt; }
     if( n>4 ) memset(&a[pc+4], 0, n-4);
     x = scrubBackupInt16(&a[pc]);
-    if( x<pc+4 && x>0 ) goto btree_corrupt;
+    if( x<pc+4 && x>0 ){ ln=__LINE__; goto btree_corrupt; }
     pc = x;
   }
 
@@ -419,18 +420,18 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
   for(i=0; i<nCell; i++){
     u32 X, M, K, nLocal;
     sqlite3_int64 P;
-    pc = scrubBackupInt16(&aCell[i]);
-    if( pc <= szHdr ) goto btree_corrupt;
-    if( pc > p->szUsable-3 ) goto btree_corrupt;
+    pc = scrubBackupInt16(&aCell[i*2]);
+    if( pc <= szHdr ){ ln=__LINE__; goto btree_corrupt; }
+    if( pc > p->szUsable-3 ){ ln=__LINE__; goto btree_corrupt; }
     if( aTop[0]==0x05 || aTop[0]==0x02 ){
-      if( pc+4 > p->szUsable ) goto btree_corrupt;
+      if( pc+4 > p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
       iChild = scrubBackupInt32(&a[pc]);
       pc += 4;
       scrubBackupBtree(p, iChild, iDepth+1);
       if( aTop[0]==0x05 ) continue;
     }
     pc += scrubBackupVarint(&a[pc], &P);
-    if( pc >= p->szUsable ) goto btree_corrupt;
+    if( pc >= p->szUsable ){ ln=__LINE__; goto btree_corrupt; }
     if( aTop[0]==0x0d ){
       X = p->szUsable - 35;
     }else{
@@ -444,10 +445,10 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
     K = M + ((P-M)%(p->szUsable-4));
     if( aTop[0]==0x0d ){
       pc += scrubBackupVarintSize(&a[pc]);
-      if( pc > (p->szUsable-4) ) goto btree_corrupt;
+      if( pc > (p->szUsable-4) ){ ln=__LINE__; goto btree_corrupt; }
     }
     nLocal = K<=X ? K : M;
-    if( pc+nLocal > p->szUsable-4 ) goto btree_corrupt;
+    if( pc+nLocal > p->szUsable-4 ){ ln=__LINE__; goto btree_corrupt; }
     iChild = scrubBackupInt32(&a[pc+nLocal]);
     scrubBackupOverflow(p, iChild, P-nLocal);
   }
@@ -463,7 +464,8 @@ static void scrubBackupBtree(ScrubState *p, int pgno, int iDepth){
   return;
 
 btree_corrupt:
-  scrubBackupErr(p, "corruption on page %d of source database", pgno);
+  scrubBackupErr(p, "corruption on page %d of source database (errid=%d)",
+                 pgno, ln);
   if( pgno>1 ) sqlite3_free(a);  
 }
 
@@ -524,7 +526,7 @@ int sqlite3_scrub_backup(
   /* Copy all of the btrees */
   scrubBackupBtree(&s, 1, 0);
   pStmt = scrubBackupPrepare(&s, s.dbSrc,
-       "SELECT rootpage FROM sqlite_master WHERE rootpage IS NOT NULL");
+       "SELECT rootpage FROM sqlite_master WHERE coalesce(rootpage,0)>0");
   if( pStmt==0 ) goto scrub_abort;
   while( sqlite3_step(pStmt)==SQLITE_ROW ){
     i = (u32)sqlite3_column_int(pStmt, 0);
index fff784287432bf0c8daa834eff35659a944fbae9..3ded6277441729c053a663889bf2921d717db092 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Finished\simplementation\scompiles,\sbut\suntested.
-D 2016-05-05T23:09:57.111
+C Working\swhen\srun\sagainst\ssqlite.fossil.
+D 2016-05-05T23:39:30.803
 F Makefile.in f59e0763ff448719fc1bd25513882b0567286317
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 306d73e854b1a92ea06e5d1e637faa5c44de53c7
@@ -215,7 +215,7 @@ F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
 F ext/misc/regexp.c a68d25c659bd2d893cd1215667bbf75ecb9dc7d4
 F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a
-F ext/misc/scrub.c 831d12a1ba776815eb946ee5a267997842384074
+F ext/misc/scrub.c 548a116cb0b4d8705eac392ab13d28fe2aebefe6
 F ext/misc/series.c e11e534ada797d5b816d7e7a93c022306563ca35
 F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52
 F ext/misc/spellfix.c bf1b922c2750698e9a3d4c50cce6974adb7e93be
@@ -1488,7 +1488,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P bdf2ec77d1542d4e9b68218f558710a3efc15823
-R 3a64deda8cf94b6b4577af97769133ef
+P aeb88bdf6fe9e5839b1503ab5740b27bc09d4842
+R 6bcd08fd9f0774891e37784b87170024
 U drh
-Z 668555cf9e940e9598a6c547736364c9
+Z cbd8d4738f2e299be1c42951defbac8d
index 73eea5130f64ec58d6541c082f39f333005e748e..fee828267f9e25bad2e04d1befdc6a843f519bc1 100644 (file)
@@ -1 +1 @@
-aeb88bdf6fe9e5839b1503ab5740b27bc09d4842
\ No newline at end of file
+b0bd9dd6255be161ea289ba6caa3fbd568128f62
\ No newline at end of file