]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Ensure that the sqlite3_scrub_backup() extension creates a backup database at least...
authordan <dan@noemail.net>
Tue, 26 Jul 2016 10:46:21 +0000 (10:46 +0000)
committerdan <dan@noemail.net>
Tue, 26 Jul 2016 10:46:21 +0000 (10:46 +0000)
FossilOrigin-Name: 483994a54dee3c7a3801e0e9d3c96fa9dbd8d2fd

ext/misc/scrub.c
manifest
manifest.uuid

index 1d21fc5389d8f08d153b55f589b4b49175940b5c..92718e23d1b09d9d165e5fd414025a5bace4672b 100644 (file)
@@ -74,6 +74,7 @@ struct ScrubState {
   u32 szPage;              /* Page size */
   u32 szUsable;            /* Usable bytes on each page */
   u32 nPage;               /* Number of pages */
+  u32 iLastPage;           /* Page number of last page written so far*/
   u8 *page1;               /* Content of page 1 */
 };
 
@@ -130,6 +131,7 @@ static void scrubBackupWrite(ScrubState *p, int pgno, const u8 *pData){
     scrubBackupErr(p, "write failed for page %d", pgno);
     p->rcErr = SQLITE_IOERR;
   }
+  if( pgno>p->iLastPage ) p->iLastPage = pgno;
 }
 
 /* Prepare a statement against the "db" database. */
@@ -541,6 +543,20 @@ int sqlite3_scrub_backup(
   }
   sqlite3_finalize(pStmt);
 
+  /* If the last page of the input db file is a free-list leaf, then the
+  ** backup file on disk is still smaller than the size indicated within 
+  ** the database header. In this case, write a page of zeroes to the 
+  ** last page of the backup database so that SQLite does not mistakenly
+  ** think the db is corrupt.  */
+  if( s.iLastPage<s.nPage ){
+    u8 *aZero = scrubBackupAllocPage(&s);
+    if( aZero ){
+      memset(aZero, 0, s.szPage);
+      scrubBackupWrite(&s, s.nPage, aZero);
+      sqlite3_free(aZero);
+    }
+  }
+
 scrub_abort:    
   /* Close the destination database without closing the transaction. If we
   ** commit, page zero will be overwritten. */
index 8ca4a9cd2c2871fbde3e056e3e964222f976265a..7f897eb9543fa8dc04e6f85625fa8d75404f557c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Copy\sthe\scache_spill\ssetting\sfrom\sthe\smain\sdatabase\sover\sto\sthe\nvacuum_db\stransient\sdatabase\swhen\srunning\sa\sVACUUM.
-D 2016-07-26T04:49:43.617
+C Ensure\sthat\sthe\ssqlite3_scrub_backup()\sextension\screates\sa\sbackup\sdatabase\sat\sleast\sas\slarge\sas\sindicated\sby\sthe\sdatabase\sheader,\seven\sif\sthe\slast\spage\sof\sthe\sinput\sdatabase\sis\sa\sfree-list\sleaf.
+D 2016-07-26T10:46:21.988
 F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a
@@ -217,7 +217,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 ea0903701e3ac02b4466ce9cffd0325c7ddbfcf0
+F ext/misc/scrub.c 1c5bfb8b0cd18b602fcb55755e84abf0023ac2fb
 F ext/misc/series.c e11e534ada797d5b816d7e7a93c022306563ca35
 F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52
 F ext/misc/spellfix.c bf1b922c2750698e9a3d4c50cce6974adb7e93be
@@ -1507,7 +1507,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 b819bace9c2a0b0159122b26db96a8f50a6f0eac
-R 2279949c9ee671e45067af58637c4ef8
-U drh
-Z ef49efbba33d277501e077ba267218c2
+P c0e7d98ef2a13ede5ae865083ede1aaffdf43310
+R 783c6677056c1c6297ef166e24fadbce
+U dan
+Z 42a389186c57610d077ea553714cade1
index 59d5af71dfd0b271d2c6968b64616c5acec2eef5..1e810448d248a53d16d378766e4162a2e9bba33d 100644 (file)
@@ -1 +1 @@
-c0e7d98ef2a13ede5ae865083ede1aaffdf43310
\ No newline at end of file
+483994a54dee3c7a3801e0e9d3c96fa9dbd8d2fd
\ No newline at end of file