/ Check-in [58d14afe]
Login

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

Overview
Comment:Add more corruption checking to the cell overwrite logic.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | cell-overwrite-prototype
Files: files | file ages | folders
SHA3-256:58d14afe1e1288d114ea213458b3121e0a95670887861928858b7f143c76f789
User & Date: drh 2018-05-03 13:56:23
Context
2018-05-03
14:07
The BtCursor.info fields are only valid if info.nSize!=0. check-in: 54c537ee user: drh tags: cell-overwrite-prototype
13:56
Add more corruption checking to the cell overwrite logic. check-in: 58d14afe user: drh tags: cell-overwrite-prototype
12:57
Bug fixes in the overwrite optimization. check-in: 0cb6cd2a user: drh tags: cell-overwrite-prototype
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/btree.c.

8197
8198
8199
8200
8201
8202
8203



8204
8205
8206
8207
8208
8209
8210
....
8211
8212
8213
8214
8215
8216
8217



8218
8219
8220
8221
8222
8223
8224
  int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
  int rc;                             /* Return code */
  MemPage *pPage = pCur->pPage;       /* Page being written */
  BtShared *pBt;                      /* Btree */
  Pgno ovflPgno;                      /* Next overflow page to write */
  u32 ovflPageSize;                   /* Size to write on overflow page */




  /* Overwrite the local portion first */
  rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
                             0, pCur->info.nLocal);
  if( rc ) return rc;
  if( pCur->info.nLocal==nTotal ) return SQLITE_OK;

  /* Now overwrite the overflow pages */
................................................................................
  iOffset = pCur->info.nLocal;
  ovflPgno = get4byte(pCur->info.pPayload + iOffset);
  pBt = pPage->pBt;
  ovflPageSize = pBt->usableSize - 4;
  do{
    rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
    if( rc ) return rc;



    if( iOffset+ovflPageSize<nTotal ){
      ovflPgno = get4byte(pPage->aData);
    }else{
      ovflPageSize = nTotal - iOffset;
    }
    rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
                               iOffset, ovflPageSize);







>
>
>







 







>
>
>







8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
....
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
  int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
  int rc;                             /* Return code */
  MemPage *pPage = pCur->pPage;       /* Page being written */
  BtShared *pBt;                      /* Btree */
  Pgno ovflPgno;                      /* Next overflow page to write */
  u32 ovflPageSize;                   /* Size to write on overflow page */

  if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd ){
    return SQLITE_CORRUPT_BKPT;
  }
  /* Overwrite the local portion first */
  rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
                             0, pCur->info.nLocal);
  if( rc ) return rc;
  if( pCur->info.nLocal==nTotal ) return SQLITE_OK;

  /* Now overwrite the overflow pages */
................................................................................
  iOffset = pCur->info.nLocal;
  ovflPgno = get4byte(pCur->info.pPayload + iOffset);
  pBt = pPage->pBt;
  ovflPageSize = pBt->usableSize - 4;
  do{
    rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
    if( rc ) return rc;
    if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
      return SQLITE_CORRUPT_BKPT;
    }
    if( iOffset+ovflPageSize<nTotal ){
      ovflPgno = get4byte(pPage->aData);
    }else{
      ovflPageSize = nTotal - iOffset;
    }
    rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
                               iOffset, ovflPageSize);