/ Check-in [440c573c]
Login

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

Overview
Comment:Simplifications to the PRAGMA integrity_check logic in btree.c. (CVS 6873)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:440c573c7e2a22f9a67a9571883e205fbadb7c11
User & Date: drh 2009-07-10 02:52:21
Context
2009-07-10
09:24
Fix a double-free that can occur when using the fts3 legacy syntax '-' operator. Add tests for the same operator. Ticket #3960. (CVS 6874) check-in: c19d419e user: danielk1977 tags: trunk
02:52
Simplifications to the PRAGMA integrity_check logic in btree.c. (CVS 6873) check-in: 440c573c user: drh tags: trunk
2009-07-09
13:25
Fix two faulty assert() statements btree. (It was possible for the assertions to be false given a corrupt database file as input.) (CVS 6872) check-in: 9403f04d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.672 2009/07/09 13:25:32 drh Exp $
           12  +** $Id: btree.c,v 1.673 2009/07/10 02:52:21 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
  7385   7385       memset(hit, 1, contentOffset);
  7386   7386       nCell = get2byte(&data[hdr+3]);
  7387   7387       cellStart = hdr + 12 - 4*pPage->leaf;
  7388   7388       for(i=0; i<nCell; i++){
  7389   7389         int pc = get2byte(&data[cellStart+i*2]);
  7390   7390         u16 size = 1024;
  7391   7391         int j;
  7392         -      if( pc<=usableSize ){
         7392  +      if( pc<=usableSize-4 ){
  7393   7393           size = cellSizePtr(pPage, &data[pc]);
  7394   7394         }
  7395   7395         if( (pc+size-1)>=usableSize || pc<0 ){
  7396   7396           checkAppendMsg(pCheck, 0, 
  7397   7397               "Corruption detected in cell %d on page %d",i,iPage,0);
  7398   7398         }else{
  7399   7399           for(j=pc+size-1; j>=pc; j--) hit[j]++;
  7400   7400         }
  7401   7401       }
  7402         -    for(cnt=0, i=get2byte(&data[hdr+1]); i>0 && i<usableSize && cnt<10000; 
  7403         -           cnt++){
  7404         -      int size = get2byte(&data[i+2]);
  7405         -      int j;
  7406         -      if( (i+size-1)>=usableSize || i<0 ){
  7407         -        checkAppendMsg(pCheck, 0,  
  7408         -            "Corruption detected in cell %d on page %d",i,iPage,0);
  7409         -      }else{
  7410         -        for(j=i+size-1; j>=i; j--) hit[j]++;
  7411         -      }
  7412         -      i = get2byte(&data[i]);
         7402  +    i = get2byte(&data[hdr+1]);
         7403  +    while( i>0 ){
         7404  +      int size, j;
         7405  +      assert( i<=usableSize-4 );     /* Enforced by btreeInitPage() */
         7406  +      size = get2byte(&data[i+2]);
         7407  +      assert( i+size<=usableSize );  /* Enforced by btreeInitPage() */
         7408  +      for(j=i+size-1; j>=i; j--) hit[j]++;
         7409  +      j = get2byte(&data[i]);
         7410  +      assert( j==0 || j>i+size );  /* Enforced by btreeInitPage() */
         7411  +      assert( j<=usableSize-4 );   /* Enforced by btreeInitPage() */
         7412  +      i = j;
  7413   7413       }
  7414   7414       for(i=cnt=0; i<usableSize; i++){
  7415   7415         if( hit[i]==0 ){
  7416   7416           cnt++;
  7417   7417         }else if( hit[i]>1 ){
  7418   7418           checkAppendMsg(pCheck, 0,
  7419   7419             "Multiple uses for byte %d of page %d", i, iPage);
  7420   7420           break;
  7421   7421         }
  7422   7422       }
  7423   7423       if( cnt!=data[hdr+7] ){
  7424   7424         checkAppendMsg(pCheck, 0, 
  7425         -          "Fragmented space is %d byte reported as %d on page %d",
         7425  +          "Fragmentation of %d bytes reported as %d on page %d",
  7426   7426             cnt, data[hdr+7], iPage);
  7427   7427       }
  7428   7428     }
  7429   7429   check_page_abort:
  7430         -  if (hit) sqlite3PageFree(hit);
  7431         -
         7430  +  sqlite3PageFree(hit);
  7432   7431     releasePage(pPage);
  7433   7432     return depth+1;
  7434   7433   }
  7435   7434   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  7436   7435   
  7437   7436   #ifndef SQLITE_OMIT_INTEGRITY_CHECK
  7438   7437   /*