mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Make sure the dbFileVers field in the Pager object is properly initialized
even if there is an I/O error while reading its content off of disk. FossilOrigin-Name: 81ff698f62c8133818a3db1997ae7427705da23f
This commit is contained in:
21
src/pager.c
21
src/pager.c
@@ -3339,6 +3339,7 @@ int sqlite3PagerOpen(
|
||||
/* pPager->pBusyHandlerArg = 0; */
|
||||
pPager->xReiniter = xReinit;
|
||||
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
|
||||
|
||||
*ppPager = pPager;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@@ -3488,8 +3489,24 @@ static int readDbPage(PgHdr *pPg){
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
if( pgno==1 ){
|
||||
u8 *dbFileVers = &((u8*)pPg->pData)[24];
|
||||
memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
|
||||
if( rc ){
|
||||
/* If the read is unsuccessful, set the dbFileVers[] to something
|
||||
** that will never be a valid file version. dbFileVers[] is a copy
|
||||
** of bytes 24..39 of the database. Bytes 28..31 should always be
|
||||
** zero. Bytes 32..35 and 35..39 should be page numbers which are
|
||||
** never 0xffffffff. So filling pPager->dbFileVers[] with all 0xff
|
||||
** bytes should suffice.
|
||||
**
|
||||
** For an encrypted database, the situation is more complex: bytes
|
||||
** 24..39 of the database are white noise. But the probability of
|
||||
** white noising equaling 16 bytes of 0xff is vanishingly small so
|
||||
** we should still be ok.
|
||||
*/
|
||||
memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
|
||||
}else{
|
||||
u8 *dbFileVers = &((u8*)pPg->pData)[24];
|
||||
memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
|
||||
}
|
||||
}
|
||||
CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM);
|
||||
|
||||
|
Reference in New Issue
Block a user