/ Check-in [5550e815]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved detection of zero page numbers in the page cache.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pcache1-zero-page
Files: files | file ages | folders
SHA1: 5550e815dd943b15c3b08f0526280bba76976199
User & Date: drh 2016-12-30 13:40:41
Context
2016-12-30
13:55
Clarify the expectations for the behavior of the xFetch method on the sqlite3_pcache_methods object for the case when the key is zero. Closed-Leaf check-in: b0810ac1 user: drh tags: pcache1-zero-page
13:40
Improved detection of zero page numbers in the page cache. check-in: 5550e815 user: drh tags: pcache1-zero-page
12:10
Fix a harmless compiler warning in fuzzcheck.c check-in: 2842bc60 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  5372   5372     assert( pPager->eState>=PAGER_READER );
  5373   5373     assert( assert_pager_state(pPager) );
  5374   5374     assert( pPager->hasHeldSharedLock==1 );
  5375   5375   
  5376   5376     pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
  5377   5377     if( pBase==0 ){
  5378   5378       pPg = 0;
  5379         -    rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
         5379  +    if( pgno==0 ){
         5380  +      rc = SQLITE_CORRUPT_BKPT;
         5381  +    }else{
         5382  +      rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
         5383  +    }
  5380   5384       if( rc!=SQLITE_OK ) goto pager_acquire_err;
  5381   5385       if( pBase==0 ){
  5382   5386         rc = SQLITE_NOMEM_BKPT;
  5383   5387         goto pager_acquire_err;
  5384   5388       }
  5385   5389     }
  5386   5390     pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
................................................................................
  5396   5400       pPager->aStat[PAGER_STAT_HIT]++;
  5397   5401       return SQLITE_OK;
  5398   5402   
  5399   5403     }else{
  5400   5404       /* The pager cache has created a new page. Its content needs to 
  5401   5405       ** be initialized. But first some error checks:
  5402   5406       **
  5403         -    ** (1) Minimum page number is 1
  5404         -    ** (2) The maximum page number is 2^31
  5405         -    ** (3) Never try to fetch the locking page
         5407  +    ** (1) The maximum page number is 2^31
         5408  +    ** (2) Never try to fetch the locking page
  5406   5409       */
  5407         -    if( pgno==0 || pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
         5410  +    assert( pgno>0 );
         5411  +    if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
  5408   5412         rc = SQLITE_CORRUPT_BKPT;
  5409   5413         goto pager_acquire_err;
  5410   5414       }
  5411   5415   
  5412   5416       pPg->pPager = pPager;
  5413   5417   
  5414   5418       assert( !isOpen(pPager->fd) || !MEMDB );

Changes to src/pcache1.c.

   993    993     ** subsequent steps to try to create the page. */
   994    994     if( pPage ){
   995    995       if( !pPage->isPinned ){
   996    996         return pcache1PinPage(pPage);
   997    997       }else{
   998    998         return pPage;
   999    999       }
  1000         -  }else if( createFlag ){
         1000  +  }else if( createFlag && iKey ){
  1001   1001       /* Steps 3, 4, and 5 implemented by this subroutine */
  1002   1002       return pcache1FetchStage2(pCache, iKey, createFlag);
  1003   1003     }else{
  1004   1004       return 0;
  1005   1005     }
  1006   1006   }
  1007   1007   #if PCACHE1_MIGHT_USE_GROUP_MUTEX