1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

If the size of the database according to the header is larger than the

actual database file size, report that the database is corrupt.

FossilOrigin-Name: 8eb1f2443f2712920452b7ed3fb835c7f3221191
This commit is contained in:
drh
2010-04-02 12:46:45 +00:00
parent cce75d3343
commit c2a4bab462
3 changed files with 24 additions and 19 deletions

View File

@@ -2230,9 +2230,11 @@ int sqlite3BtreeGetAutoVacuum(Btree *p){
** is returned if we run out of memory.
*/
static int lockBtree(BtShared *pBt){
int rc;
MemPage *pPage1;
int nPage;
int rc; /* Result code from subfunctions */
MemPage *pPage1; /* Page 1 of the database file */
int nPage; /* Number of pages in the database */
int nPageFile = 0; /* Number of pages in the database file */
int nPageHeader; /* Number of pages in the database according to hdr */
assert( sqlite3_mutex_held(pBt->mutex) );
assert( pBt->pPage1==0 );
@@ -2244,13 +2246,12 @@ static int lockBtree(BtShared *pBt){
/* Do some checking to help insure the file we opened really is
** a valid database file.
*/
nPage = get4byte(28+(u8*)pPage1->aData);
nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
goto page1_init_failed;
}
if( nPage==0 ){
rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
/* The sqlite3PagerSharedLock() call above has already determined
** the database file size, so this call to sqlite3PagerPagecount()
** cannot fail. */
if( NEVER(rc) ) goto page1_init_failed;
nPage = nPageFile;
}
if( nPage>0 ){
int pageSize;
@@ -2298,6 +2299,10 @@ static int lockBtree(BtShared *pBt){
pageSize-usableSize);
return rc;
}
if( nPageHeader>nPageFile ){
rc = SQLITE_CORRUPT_BKPT;
goto page1_init_failed;
}
if( usableSize<480 ){
goto page1_init_failed;
}