/ Check-in [02d99ad4]
Login

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

Overview
Comment:Make sure a WAL frame of all zeros is detected as an invalid frame.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 02d99ad4b51065c67cc7689916130774be1c4c87
User & Date: drh 2010-05-24 13:28:36
Context
2010-05-24
13:57
Change the checksum used in WAL files so that each frames checksum depends on the content of the WAL header and all frame headers and content up to and including the frame to which the checksum is attached. check-in: 8a53f12c user: dan tags: trunk
13:28
Make sure a WAL frame of all zeros is detected as an invalid frame. check-in: 02d99ad4 user: drh tags: trunk
12:34
Fix up test_osinst.c to work with SQLITE_OMIT_VIRTUALTABLE. check-in: 51fd3815 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/wal.c.

   447    447     Wal *pWal,                      /* The write-ahead log */
   448    448     u32 *piPage,                    /* OUT: Database page number for frame */
   449    449     u32 *pnTruncate,                /* OUT: New db size (or 0 if not commit) */
   450    450     u8 *aData,                      /* Pointer to page data (for checksum) */
   451    451     u8 *aFrame                      /* Frame data */
   452    452   ){
   453    453     int nativeCksum;                /* True for native byte-order checksums */
          454  +  u32 pgno;                       /* Page number of the frame */
   454    455     u32 aCksum[2];
   455    456     assert( WAL_FRAME_HDRSIZE==24 );
   456    457   
   457    458     /* A frame is only valid if the salt values in the frame-header
   458    459     ** match the salt values in the wal-header. 
   459    460     */
   460    461     if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
   461    462       return 0;
   462    463     }
          464  +
          465  +  /* A frame is only valid if the page number is creater than zero.
          466  +  */
          467  +  pgno = sqlite3Get4byte(&aFrame[0]);
          468  +  if( pgno==0 ){
          469  +    return 0;
          470  +  }
   463    471   
   464    472     /* A frame is only valid if a checksum of the first 16 bytes
   465    473     ** of the frame-header, and the frame-data matches
   466    474     ** the checksum in the last 8 bytes of the frame-header.
   467    475     */
   468    476     nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
   469    477     walChecksumBytes(nativeCksum, aFrame, 16, 0, aCksum);
................................................................................
   474    482       /* Checksum failed. */
   475    483       return 0;
   476    484     }
   477    485   
   478    486     /* If we reach this point, the frame is valid.  Return the page number
   479    487     ** and the new database size.
   480    488     */
   481         -  *piPage = sqlite3Get4byte(&aFrame[0]);
          489  +  *piPage = pgno;
   482    490     *pnTruncate = sqlite3Get4byte(&aFrame[4]);
   483    491     return 1;
   484    492   }
   485    493   
   486    494   /*
   487    495   ** Define the parameters of the hash tables in the wal-index file. There
   488    496   ** is a hash-table following every HASHTABLE_NPAGE page numbers in the