From: dan Date: Tue, 26 Jul 2016 10:46:21 +0000 (+0000) Subject: Ensure that the sqlite3_scrub_backup() extension creates a backup database at least... X-Git-Tag: version-3.14.0~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2900a6222f475f4d495c302aa5d5aab3dc1f0237;p=thirdparty%2Fsqlite.git Ensure that the sqlite3_scrub_backup() extension creates a backup database at least as large as indicated by the database header, even if the last page of the input database is a free-list leaf. FossilOrigin-Name: 483994a54dee3c7a3801e0e9d3c96fa9dbd8d2fd --- diff --git a/ext/misc/scrub.c b/ext/misc/scrub.c index 1d21fc5389..92718e23d1 100644 --- a/ext/misc/scrub.c +++ b/ext/misc/scrub.c @@ -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