/ Check-in [56bff6eb]
Login

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

Overview
Comment:Enable cell overflow checking in sqlite3BtreeInitPage() using the compile-time option SQLITE_ENABLE_OVERSIZE_CELL_CHECK. Change the tests so that they recognize different error messages depending on the setting of this macro. (CVS 6735)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:56bff6eb2fc5f0afbd96afc986671ec744bd40e1
User & Date: drh 2009-06-09 13:42:25
Context
2009-06-09
14:27
Modify mkkeywordhash.c so that it puts the original text of each token in a comment beside the "testcase()" macros. (CVS 6736) check-in: a7d0817c user: drh tags: trunk
13:42
Enable cell overflow checking in sqlite3BtreeInitPage() using the compile-time option SQLITE_ENABLE_OVERSIZE_CELL_CHECK. Change the tests so that they recognize different error messages depending on the setting of this macro. (CVS 6735) check-in: 56bff6eb user: drh tags: trunk
11:34
Avoid calling fillInCell() to create an internal node intkey cell from balance_nonroot(). A single putVarint() does the same thing more quickly. (CVS 6734) check-in: 2e5d42ae user: danielk1977 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.623 2009/06/09 11:34:11 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.624 2009/06/09 13:42:25 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   
................................................................................
  1149   1149       /* A malformed database page might cause use to read past the end
  1150   1150       ** of page when parsing a cell.  
  1151   1151       **
  1152   1152       ** The following block of code checks early to see if a cell extends
  1153   1153       ** past the end of a page boundary and causes SQLITE_CORRUPT to be 
  1154   1154       ** returned if it does.
  1155   1155       */
  1156         -#if defined(SQLITE_OVERREAD_CHECK)
         1156  +#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
  1157   1157       {
  1158   1158         int iCellFirst;   /* First allowable cell index */
  1159   1159         int iCellLast;    /* Last possible cell index */
  1160   1160         int i;            /* Index into the cell pointer array */
  1161   1161         int sz;           /* Size of a cell */
  1162   1162   
  1163   1163         iCellFirst = cellOffset + 2*pPage->nCell;

Changes to src/test_config.c.

    12     12   ** 
    13     13   ** This file contains code used for testing the SQLite system.
    14     14   ** None of the code in this file goes into a deliverable build.
    15     15   ** 
    16     16   ** The focus of this file is providing the TCL testing layer
    17     17   ** access to compile-time constants.
    18     18   **
    19         -** $Id: test_config.c,v 1.48 2009/03/16 13:19:36 danielk1977 Exp $
           19  +** $Id: test_config.c,v 1.49 2009/06/09 13:42:25 drh Exp $
    20     20   */
    21     21   
    22     22   #include "sqliteLimit.h"
    23     23   
    24     24   #include "sqliteInt.h"
    25     25   #include "tcl.h"
    26     26   #include <stdlib.h>
................................................................................
   172    172   #endif
   173    173   
   174    174   #ifdef SQLITE_ENABLE_COLUMN_METADATA
   175    175     Tcl_SetVar2(interp, "sqlite_options", "columnmetadata", "1", TCL_GLOBAL_ONLY);
   176    176   #else
   177    177     Tcl_SetVar2(interp, "sqlite_options", "columnmetadata", "0", TCL_GLOBAL_ONLY);
   178    178   #endif
          179  +
          180  +#ifdef SQLITE_ENABLE_OVERSIZE_CELL_CHECK
          181  +  Tcl_SetVar2(interp, "sqlite_options", "oversize_cell_check", "1",
          182  +              TCL_GLOBAL_ONLY);
          183  +#else
          184  +  Tcl_SetVar2(interp, "sqlite_options", "oversize_cell_check", "0",
          185  +              TCL_GLOBAL_ONLY);
          186  +#endif
          187  +
          188  +
   179    189   
   180    190   #ifdef SQLITE_OMIT_COMPLETE
   181    191     Tcl_SetVar2(interp, "sqlite_options", "complete", "0", TCL_GLOBAL_ONLY);
   182    192   #else
   183    193     Tcl_SetVar2(interp, "sqlite_options", "complete", "1", TCL_GLOBAL_ONLY);
   184    194   #endif
   185    195   

Changes to test/corrupt7.test.

    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests to make sure SQLite does not crash or
    14     14   # segfault if it sees a corrupt database file.  It specifically focuses
    15     15   # on corrupt cell offsets in a btree page.
    16     16   #
    17         -# $Id: corrupt7.test,v 1.6 2009/06/04 17:02:51 drh Exp $
           17  +# $Id: corrupt7.test,v 1.7 2009/06/09 13:42:25 drh Exp $
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # We must have the page_size pragma for these tests to work.
    23     23   #
    24     24   ifcapable !pager_pragmas {
................................................................................
    53     53   } 0      ;# Unused bytes per page is 0
    54     54   
    55     55   integrity_check corrupt7-1.4
    56     56   
    57     57   # Deliberately corrupt some of the cell offsets in the btree page
    58     58   # on page 2 of the database.
    59     59   #
    60         -do_test corrupt7-2.1 {
    61         -  db close
    62         -  hexio_write test.db 1062 FF
    63         -  sqlite3 db test.db
    64         -  db eval {PRAGMA integrity_check(1)}
    65         -} {{*** in database main ***
           60  +# The error message is different depending on whether or not the
           61  +# SQLITE_ENABLE_OVERSIZE_CELL_CHECK compile-time option is engaged.
           62  +#
           63  +ifcapable oversize_cell_check {
           64  +  do_test corrupt7-2.1 {
           65  +    db close
           66  +    hexio_write test.db 1062 FF
           67  +    sqlite3 db test.db
           68  +    db eval {PRAGMA integrity_check(1)}
           69  +  } {{*** in database main ***
    66     70   Page 2: sqlite3BtreeInitPage() returns error code 11}}
    67         -do_test corrupt7-2.2 {
    68         -  db close
    69         -  hexio_write test.db 1062 04
    70         -  sqlite3 db test.db
    71         -  db eval {PRAGMA integrity_check(1)}
    72         -} {{*** in database main ***
           71  +  do_test corrupt7-2.2 {
           72  +    db close
           73  +    hexio_write test.db 1062 04
           74  +    sqlite3 db test.db
           75  +    db eval {PRAGMA integrity_check(1)}
           76  +  } {{*** in database main ***
    73     77   Page 2: sqlite3BtreeInitPage() returns error code 11}}
    74         -
           78  +} else {
           79  +  do_test corrupt7-2.1 {
           80  +    db close
           81  +    hexio_write test.db 1062 FF
           82  +    sqlite3 db test.db
           83  +    db eval {PRAGMA integrity_check(1)}
           84  +  } {{*** in database main ***
           85  +Corruption detected in cell 15 on page 2}}
           86  +  do_test corrupt7-2.2 {
           87  +    db close
           88  +    hexio_write test.db 1062 04
           89  +    sqlite3 db test.db
           90  +    db eval {PRAGMA integrity_check(1)}
           91  +  } {{*** in database main ***
           92  +Corruption detected in cell 15 on page 2}}
           93  +}
           94  +  
    75     95   # The code path that was causing the buffer overrun that this test
    76     96   # case was checking for was removed.
    77     97   #
    78     98   #do_test corrupt7-3.1 {
    79     99   #  execsql {
    80    100   #    DROP TABLE t1;
    81    101   #    CREATE TABLE t1(a, b);