Skip to content

Commit

Permalink
Earlier detection of out-of-range page numbers in the btree layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
D. Richard Hipp committed Jul 28, 2020
1 parent b662892 commit 65adfb6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6290,6 +6290,10 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
u32 nLeaf; /* Initial number of leaf cells on trunk page */

iTrunk = get4byte(&pPage1->aData[32]);
if( iTrunk>btreePagecount(pBt) ){
rc = SQLITE_CORRUPT_BKPT;
goto freepage_out;
}
rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
if( rc!=SQLITE_OK ){
goto freepage_out;
Expand Down Expand Up @@ -9127,6 +9131,9 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
** created so far, so the new root-page is (meta[3]+1).
*/
sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
if( pgnoRoot>btreePagecount(pBt) ){
return SQLITE_CORRUPT_BKPT;
}
pgnoRoot++;

/* The new root-page may not be allocated on a pointer-map page, or the
Expand Down

0 comments on commit 65adfb6

Please sign in to comment.