SQLite

Check-in [3a09f5605a]
Login

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

Overview
Comment:Update some test cases that deal with corrupt databases.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 3a09f5605ac7c6e503eb10acfdc607010414d917
User & Date: dan 2014-02-28 18:39:51.462
Context
2014-03-01
19:44
Remove the vdbeRecordCompareLargeHeader function. Fix some other details. (check-in: 3861e85310 user: dan tags: experimental)
2014-02-28
18:39
Update some test cases that deal with corrupt databases. (check-in: 3a09f5605a user: dan tags: experimental)
09:48
Minor tweak to vdbeRecordCompareInt(). (check-in: 284bde0ee2 user: dan tags: experimental)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeaux.c.
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
    case 9:
      lhs = 1;
      break;

    /* This case could be removed without changing the results of running
    ** this code. Including it causes gcc to generate a faster switch 
    ** statement (since the range of switch targets now starts at zero and
    ** is contiguous)) but does not cause any duplicate code to be generated
    ** (as gcc is clever enough to combine the two like cases). Other 
    ** compilers might be similar.  */ 
    case 0: case 7:
      return vdbeRecordCompare(nKey1, pKey1, szHdr, 1, pPKey2);

    default:
      return vdbeRecordCompare(nKey1, pKey1, szHdr, 1, pPKey2);







|







3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
    case 9:
      lhs = 1;
      break;

    /* This case could be removed without changing the results of running
    ** this code. Including it causes gcc to generate a faster switch 
    ** statement (since the range of switch targets now starts at zero and
    ** is contiguous) but does not cause any duplicate code to be generated
    ** (as gcc is clever enough to combine the two like cases). Other 
    ** compilers might be similar.  */ 
    case 0: case 7:
      return vdbeRecordCompare(nKey1, pKey1, szHdr, 1, pPKey2);

    default:
      return vdbeRecordCompare(nKey1, pKey1, szHdr, 1, pPKey2);
Changes to src/vdbemem.c.
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
      nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
      pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
      if( pRec ){
        pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
        if( pRec->pKeyInfo ){
          assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
          assert( pRec->pKeyInfo->enc==ENC(db) );
          pRec->flags = UNPACKED_PREFIX_MATCH;
          pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
          for(i=0; i<nCol; i++){
            pRec->aMem[i].flags = MEM_Null;
            pRec->aMem[i].memType = MEM_Null;
            pRec->aMem[i].db = db;
          }
        }else{







<







909
910
911
912
913
914
915

916
917
918
919
920
921
922
      nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
      pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
      if( pRec ){
        pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
        if( pRec->pKeyInfo ){
          assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
          assert( pRec->pKeyInfo->enc==ENC(db) );

          pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
          for(i=0; i<nCol; i++){
            pRec->aMem[i].flags = MEM_Null;
            pRec->aMem[i].memType = MEM_Null;
            pRec->aMem[i].db = db;
          }
        }else{
Changes to test/analyze9.test.
322
323
324
325
326
327
328

329
330
331
332
333
334
335
#-------------------------------------------------------------------------
# The following tests experiment with adding corrupted records to the
# 'sample' column of the sqlite_stat4 table.
#
reset_db
sqlite3_db_config_lookaside db 0 0 0


do_execsql_test 7.1 {
  CREATE TABLE t1(a, b);
  CREATE INDEX i1 ON t1(a, b);
  INSERT INTO t1 VALUES(1, 1);
  INSERT INTO t1 VALUES(2, 2);
  INSERT INTO t1 VALUES(3, 3);
  INSERT INTO t1 VALUES(4, 4);







>







322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#-------------------------------------------------------------------------
# The following tests experiment with adding corrupted records to the
# 'sample' column of the sqlite_stat4 table.
#
reset_db
sqlite3_db_config_lookaside db 0 0 0

database_may_be_corrupt
do_execsql_test 7.1 {
  CREATE TABLE t1(a, b);
  CREATE INDEX i1 ON t1(a, b);
  INSERT INTO t1 VALUES(1, 1);
  INSERT INTO t1 VALUES(2, 2);
  INSERT INTO t1 VALUES(3, 3);
  INSERT INTO t1 VALUES(4, 4);
361
362
363
364
365
366
367


368
369
370
371
372
373
374

do_execsql_test 7.5 {
  ANALYZE;
  UPDATE sqlite_stat4 SET nlt = '0 0 0';
  ANALYZE sqlite_master;
  SELECT * FROM t1 WHERE a = 5;
} {5 5}



#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 8.1 {
  CREATE TABLE t1(x TEXT);
  CREATE INDEX i1 ON t1(x);







>
>







362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377

do_execsql_test 7.5 {
  ANALYZE;
  UPDATE sqlite_stat4 SET nlt = '0 0 0';
  ANALYZE sqlite_master;
  SELECT * FROM t1 WHERE a = 5;
} {5 5}

database_never_corrupt

#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 8.1 {
  CREATE TABLE t1(x TEXT);
  CREATE INDEX i1 ON t1(x);
Changes to test/corruptG.test.
72
73
74
75
76
77
78
79
80
81
    SELECT rowid FROM t1 WHERE a='abc' and b='xyz123456789XYZ';
  }
  # The following test result is brittle.  The point above is to try to
  # force a buffer overread by a corrupt database file.  If we get an
  # incorrect answer from a corrupt database file, that is OK.  If the
  # result below changes, that just means that "undefined behavior" has
  # changed.
} {0 52}

finish_test







|


72
73
74
75
76
77
78
79
80
81
    SELECT rowid FROM t1 WHERE a='abc' and b='xyz123456789XYZ';
  }
  # The following test result is brittle.  The point above is to try to
  # force a buffer overread by a corrupt database file.  If we get an
  # incorrect answer from a corrupt database file, that is OK.  If the
  # result below changes, that just means that "undefined behavior" has
  # changed.
} {/0 .*/}

finish_test
Changes to test/pragma.test.
1598
1599
1600
1601
1602
1603
1604





1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
} {100}

set mainerr {*** in database main ***
Multiple uses for byte 672 of page 15}
set auxerr {*** in database aux ***
Multiple uses for byte 672 of page 15}






do_test 22.2 {
  catch { db close }
  sqlite3 db testerr.db
  execsql { PRAGMA integrity_check }
} [list $mainerr]

do_test 22.3.1 {
  catch { db close }
  sqlite3 db test.db
  execsql { 
    ATTACH 'testerr.db' AS 'aux';
    PRAGMA integrity_check;
  }
} [list $auxerr]
do_test 22.3.2 {
  execsql { PRAGMA main.integrity_check; }
} {ok}
do_test 22.3.3 {
  execsql { PRAGMA aux.integrity_check; }
} [list $auxerr]

do_test 22.4.1 {
  catch { db close }
  sqlite3 db testerr.db
  execsql { 
    ATTACH 'test.db' AS 'aux';
    PRAGMA integrity_check;
  }
} [list $mainerr]
do_test 22.4.2 {
  execsql { PRAGMA main.integrity_check; }
} [list $mainerr]
do_test 22.4.3 {
  execsql { PRAGMA aux.integrity_check; }
} {ok}

db close
forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db







>
>
>
>
>




|








|





|








|


|







1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
} {100}

set mainerr {*** in database main ***
Multiple uses for byte 672 of page 15}
set auxerr {*** in database aux ***
Multiple uses for byte 672 of page 15}

set mainerr {/{\*\*\* in database main \*\*\*
Multiple uses for byte 672 of page 15}.*/}
set auxerr {/{\*\*\* in database aux \*\*\*
Multiple uses for byte 672 of page 15}.*/}

do_test 22.2 {
  catch { db close }
  sqlite3 db testerr.db
  execsql { PRAGMA integrity_check }
} $mainerr

do_test 22.3.1 {
  catch { db close }
  sqlite3 db test.db
  execsql { 
    ATTACH 'testerr.db' AS 'aux';
    PRAGMA integrity_check;
  }
} $auxerr
do_test 22.3.2 {
  execsql { PRAGMA main.integrity_check; }
} {ok}
do_test 22.3.3 {
  execsql { PRAGMA aux.integrity_check; }
} $auxerr

do_test 22.4.1 {
  catch { db close }
  sqlite3 db testerr.db
  execsql { 
    ATTACH 'test.db' AS 'aux';
    PRAGMA integrity_check;
  }
} $mainerr
do_test 22.4.2 {
  execsql { PRAGMA main.integrity_check; }
} $mainerr
do_test 22.4.3 {
  execsql { PRAGMA aux.integrity_check; }
} {ok}

db close
forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db