SQLite

Check-in [a7b7b126e9]
Login

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

Overview
Comment:If the 'rootpage' column of the sqlite_master table contains a NULL value, return SQLITE_CORRUPT to the caller. (CVS 5681)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a7b7b126e9e9b0cd2d68643d8dff321cf41ce2ee
User & Date: danielk1977 2008-09-08 09:06:19.000
Context
2008-09-08
11:07
Fix a bug in r-tree related to internal nodes with one or more dimensions of size zero. Ticket #3363. (CVS 5682) (check-in: 8b600ed083 user: danielk1977 tags: trunk)
09:06
If the 'rootpage' column of the sqlite_master table contains a NULL value, return SQLITE_CORRUPT to the caller. (CVS 5681) (check-in: a7b7b126e9 user: danielk1977 tags: trunk)
08:08
Add header file sqliteicu.h to the ICU extension. This is analogous to the rtree.h and fts3.h headers used by other extensions to declare their entry points. Fix for ticket #3361. (CVS 5680) (check-in: 79364b963b user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/prepare.c.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.96 2008/09/04 12:03:43 shane Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates
** that the database is corrupt.







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.97 2008/09/08 09:06:19 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Fill the InitData structure with an error message that indicates
** that the database is corrupt.
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
  DbClearProperty(db, iDb, DB_Empty);
  if( db->mallocFailed ){
    corruptSchema(pData, argv[0], 0);
    return SQLITE_NOMEM;
  }

  assert( argc==3 );

  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */
  if( argv[1]==0 ){
    corruptSchema(pData, argv[0], 0);
    return 1;
  }
  assert( iDb>=0 && iDb<db->nDb );
  if( argv[2] && argv[2][0] ){
    /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
    ** But because db->init.busy is set to 1, no VDBE code is generated
    ** or executed.  All the parser does is build the internal data
    ** structures that describe the table, index, or view.
    */
    char *zErr;
    int rc;







>



<
<
<
|







61
62
63
64
65
66
67
68
69
70
71



72
73
74
75
76
77
78
79
  DbClearProperty(db, iDb, DB_Empty);
  if( db->mallocFailed ){
    corruptSchema(pData, argv[0], 0);
    return SQLITE_NOMEM;
  }

  assert( argc==3 );
  assert( iDb>=0 && iDb<db->nDb );
  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */
  if( argv[1]==0 ){
    corruptSchema(pData, argv[0], 0);



  }else if( argv[2] && argv[2][0] ){
    /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
    ** But because db->init.busy is set to 1, no VDBE code is generated
    ** or executed.  All the parser does is build the internal data
    ** structures that describe the table, index, or view.
    */
    char *zErr;
    int rc;
Changes to test/corrupt2.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.15 2008/08/27 16:14:21 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.16 2008/09/08 09:06:19 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#
228
229
230
231
232
233
234

235
236
237
238
239
240
241
On tree page 2 cell 0: 2nd reference to page 10
On tree page 2 cell 1: Child page depth differs
Page 4 is never used}}

db2 close

proc corruption_test {args} {

  array set A $args

  catch {db close}
  file delete -force corrupt.db
  file delete -force corrupt.db-journal

  sqlite3 db corrupt.db 







>







228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
On tree page 2 cell 0: 2nd reference to page 10
On tree page 2 cell 1: Child page depth differs
Page 4 is never used}}

db2 close

proc corruption_test {args} {
  set A(-corrupt) {}
  array set A $args

  catch {db close}
  file delete -force corrupt.db
  file delete -force corrupt.db-journal

  sqlite3 db corrupt.db 
435
436
437
438
439
440
441
442














443
  puts -nonewline $fd "\x00\x00"
  close $fd
} -test {
  do_test corrupt2-9.1 {
    catchsql { SELECT sql FROM sqlite_master }
  } {1 {database disk image is malformed}}
}















finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  puts -nonewline $fd "\x00\x00"
  close $fd
} -test {
  do_test corrupt2-9.1 {
    catchsql { SELECT sql FROM sqlite_master }
  } {1 {database disk image is malformed}}
}

corruption_test -sqlprep {
  CREATE TABLE t1(a, b, c);
  CREATE TABLE t2(a, b, c);
  PRAGMA writable_schema = 1;
  UPDATE sqlite_master SET rootpage = NULL WHERE name = 't2';
} -test {
  do_test corrupt2-10.1 {
    catchsql { SELECT * FROM t2 }
  } {1 {malformed database schema (t2)}}
  do_test corrupt2-10.2 {
    sqlite3_errcode db
  } {SQLITE_CORRUPT}
}

finish_test