/ Check-in [3f45b819]
Login

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

Overview
Comment:Fix an assert that can fail if the database file is corrupted.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3f45b8192dad7fb1f027cbaa694046e3c1b3e278
User & Date: dan 2014-08-14 19:53:37
Context
2014-08-15
11:46
Version 3.8.6 check-in: 9491ba7d user: drh tags: trunk, release, version-3.8.6
2014-08-14
19:53
Fix an assert that can fail if the database file is corrupted. check-in: 3f45b819 user: dan tags: trunk
13:06
Fix typos in comments used to help generate documentation. No changes to code. check-in: 13a2d90a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  5737   5737     int cellOffset;   /* Address of first cell pointer in data[] */
  5738   5738     u8 *data;         /* The content of the whole page */
  5739   5739     int nSkip = (iChild ? 4 : 0);
  5740   5740   
  5741   5741     if( *pRC ) return;
  5742   5742   
  5743   5743     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
  5744         -  assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921 );
         5744  +  assert( MX_CELL(pPage->pBt)<=10921 );
         5745  +  assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
  5745   5746     assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
  5746   5747     assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
  5747   5748     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  5748   5749     /* The cell should normally be sized correctly.  However, when moving a
  5749   5750     ** malformed cell from a leaf page to an interior page, if the cell size
  5750   5751     ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
  5751   5752     ** might be less than 8 (leaf-size + pointer) on the interior node.  Hence

Changes to test/corruptI.test.

    71     71     catchsql { SELECT * FROM r WHERE x >= 10.0 }
    72     72   } {1 {database disk image is malformed}}
    73     73   
    74     74   do_test 2.2 {
    75     75     catchsql { SELECT * FROM r WHERE x >= 10 }
    76     76   } {1 {database disk image is malformed}}
    77     77   
           78  +reset_db
           79  +
           80  +do_execsql_test 3.1 {
           81  +  PRAGMA page_size = 512;
           82  +  CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
           83  +  WITH s(a, b) AS (
           84  +    SELECT 2, 'abcdefghij'
           85  +    UNION ALL
           86  +    SELECT a+2, b FROM s WHERe a < 40
           87  +  )
           88  +  INSERT INTO t1 SELECT * FROM s;
           89  +} {}
           90  +
           91  +do_test 3.2 {
           92  +  hexio_write test.db [expr 512+3] 0054
           93  +  db close
           94  +  sqlite3 db test.db
           95  +  execsql { INSERT INTO t1 VALUES(5, 'klmnopqrst') }
           96  +  execsql { INSERT INTO t1 VALUES(7, 'klmnopqrst') }
           97  +} {}
           98  +
           99  +db close
          100  +sqlite3 db test.db
          101  +do_catchsql_test 3.2 {
          102  +  INSERT INTO t1 VALUES(9, 'klmnopqrst');
          103  +} {1 {database disk image is malformed}}
    78    104   
    79    105   finish_test