3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to make sure SQLite does not crash or
14 # segfault if it sees a corrupt database file.
16 # $Id: corrupt2.test,v 1.2 2005/01/22 03:39:39 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # The following tests - corrupt2-1.* - create some databases corrupted in
22 # specific ways and ensure that SQLite detects them as corrupt.
24 do_test corrupt2-1.1 {
26 CREATE TABLE abc(a, b, c);
30 do_test corrupt2-1.2 {
32 # Corrupt the 16 byte magic string at the start of the file
33 file delete -force corrupt.db
34 file delete -force corrupt.db-journal
35 copy_file test.db corrupt.db
36 set f [open corrupt.db a]
41 sqlite3 db2 corrupt.db
43 SELECT * FROM sqlite_master;
45 } {1 {file is encrypted or is not a database}}
47 do_test corrupt2-1.3 {
50 # Corrupt the page-size (bytes 16 and 17 of page 1).
51 file delete -force corrupt.db
52 file delete -force corrupt.db-journal
53 copy_file test.db corrupt.db
54 set f [open corrupt.db a]
55 fconfigure $f -encoding binary
57 puts -nonewline $f "\x00\xFF"
60 sqlite3 db2 corrupt.db
62 SELECT * FROM sqlite_master;
64 } {1 {file is encrypted or is not a database}}
66 do_test corrupt2-1.4 {
69 # Corrupt the free-block list on page 1.
70 file delete -force corrupt.db
71 file delete -force corrupt.db-journal
72 copy_file test.db corrupt.db
73 set f [open corrupt.db a]
74 fconfigure $f -encoding binary
76 puts -nonewline $f "\xFF\xFF"
79 sqlite3 db2 corrupt.db
81 SELECT * FROM sqlite_master;
83 } {1 {database disk image is malformed}}
85 do_test corrupt2-1.5 {
88 # Corrupt the free-block list on page 1.
89 file delete -force corrupt.db
90 file delete -force corrupt.db-journal
91 copy_file test.db corrupt.db
92 set f [open corrupt.db a]
93 fconfigure $f -encoding binary
95 puts -nonewline $f "\x00\xC8"
97 puts -nonewline $f "\x00\x00"
98 puts -nonewline $f "\x10\x00"
101 sqlite3 db2 corrupt.db
103 SELECT * FROM sqlite_master;
105 } {1 {database disk image is malformed}}