Index: test/corrupt2.test ================================================================== --- test/corrupt2.test +++ test/corrupt2.test @@ -11,11 +11,11 @@ # 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.6 2008/07/07 15:39:11 danielk1977 Exp $ +# $Id: corrupt2.test,v 1.7 2008/07/07 17:04:23 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # The following tests - corrupt2-1.* - create some databases corrupted in @@ -167,10 +167,58 @@ sqlite3 db2 corrupt.db catchsql { DROP TABLE t1; } db2 -} {1 {malformed database schema (a3) - index a3 already exists}} +} {1 {database disk image is malformed}} + +do_test corrupt2-4.1 { + file delete -force corrupt.db + file delete -force corrupt.db-journal + sqlite3 db2 corrupt.db + + execsql { + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(randomblob(100), randomblob(100), randomblob(100)); + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t1 SELECT * FROM t2; + } db2 + + db2 close + + # This block links a page from table t2 into the t1 table structure. + # + set fd [open corrupt.db r+] + fconfigure $fd -encoding binary -translation binary + seek $fd [expr 1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 1024 + $iCelloffset] + set zChildPage [read $fd 4] + seek $fd [expr 2*1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 2*1024 + $iCelloffset] + puts -nonewline $fd $zChildPage + close $fd + + sqlite3 db2 corrupt.db + db2 eval {SELECT rowid FROM t1} { + set result [db2 eval {pragma integrity_check}] + break + } + set result +} {{*** in database main *** +Page 10: sqlite3BtreeInitPage() returns error code 11 +On tree page 3 cell 1: Child page depth differs +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 finish_test