1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Store the MemPage structure in memory following, instead of preceding, the page data for cached pages. This reduces the likelihood of a corrupt database page image causing SQLite to read past the end of a buffer.

FossilOrigin-Name: 0ce42e76654d9ba52dac74c940d38b17866016ba
This commit is contained in:
dan
2010-06-10 06:53:26 +00:00
parent 0350c7fa26
commit 026e598d0f
4 changed files with 26 additions and 23 deletions

View File

@@ -260,15 +260,17 @@ int sqlite3PcacheFetch(
if( pPage ){
if( !pPage->pData ){
memset(pPage, 0, sizeof(PgHdr) + pCache->szExtra);
pPage->pExtra = (void*)&pPage[1];
pPage->pData = (void *)&((char *)pPage)[sizeof(PgHdr) + pCache->szExtra];
memset(pPage, 0, sizeof(PgHdr));
pPage->pData = (void *)&pPage[1];
pPage->pExtra = (void*)&((char *)pPage->pData)[pCache->szPage];
memset(pPage->pExtra, 0, pCache->szExtra);
pPage->pCache = pCache;
pPage->pgno = pgno;
}
assert( pPage->pCache==pCache );
assert( pPage->pgno==pgno );
assert( pPage->pExtra==(void *)&pPage[1] );
assert( pPage->pData==(void *)&pPage[1] );
assert( pPage->pExtra==(void *)&((char *)&pPage[1])[pCache->szPage] );
if( 0==pPage->nRef ){
pCache->nRef++;