Annotation of embedaddon/sqlite3/test/corruptE.test, revision 1.1.1.1
1.1 misho 1: # 2010 February 18
2: #
3: # The author disclaims copyright to this source code. In place of
4: # a legal notice, here is a blessing:
5: #
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.
9: #
10: #***********************************************************************
11: # This file implements regression tests for SQLite library.
12: #
13: # This file implements tests to make sure SQLite does not crash or
14: # segfault if it sees a corrupt database file. It specifcally
15: # focuses on rowid order corruption.
16: #
17: # $Id: corruptE.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $
18:
19: set testdir [file dirname $argv0]
20: source $testdir/tester.tcl
21:
22: # Do not use a codec for tests in this file, as the database file is
23: # manipulated directly using tcl scripts (using the [hexio_write] command).
24: #
25: do_not_use_codec
26:
27: # Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on.
28: #
29: ifcapable oversize_cell_check {
30: finish_test
31: return
32: }
33:
34: # Construct a compact, dense database for testing.
35: #
36: do_test corruptE-1.1 {
37: execsql {
38: PRAGMA auto_vacuum = 0;
39: PRAGMA legacy_file_format=1;
40: BEGIN;
41: CREATE TABLE t1(x,y);
42: INSERT INTO t1 VALUES(1,1);
43: INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1;
44: INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1;
45: INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1;
46: INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1;
47: INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1;
48: INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1;
49: INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1;
50: INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1;
51: CREATE INDEX t1i1 ON t1(x);
52: CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0;
53: COMMIT;
54: }
55: } {}
56:
57: ifcapable {integrityck} {
58: integrity_check corruptE-1.2
59: }
60:
61: # Setup for the tests. Make a backup copy of the good database in test.bu.
62: #
63: db close
64: forcecopy test.db test.bu
65: sqlite3 db test.db
66: set fsize [file size test.db]
67:
68:
69: do_test corruptE-2.1 {
70: db close
71: forcecopy test.bu test.db
72:
73: # insert corrupt byte(s)
74: hexio_write test.db 2041 [format %02x 0x2e]
75:
76: sqlite3 db test.db
77:
78: set res [ catchsql {PRAGMA integrity_check} ]
79: set ans [lindex $res 1]
80:
81: list [regexp {out of order.*previous was} $ans] \
82: [regexp {out of order.*max larger than parent max} $ans]
83: } {1 1}
84:
85: do_test corruptE-2.2 {
86: db close
87: forcecopy test.bu test.db
88:
89: # insert corrupt byte(s)
90: hexio_write test.db 2047 [format %02x 0x84]
91:
92: sqlite3 db test.db
93:
94: set res [ catchsql {PRAGMA integrity_check} ]
95: set ans [lindex $res 1]
96:
97: list [regexp {out of order.*previous was} $ans] \
98: [regexp {out of order.*min less than parent min} $ans]
99: } {1 1}
100:
101: do_test corruptE-2.3 {
102: db close
103: forcecopy test.bu test.db
104:
105: # insert corrupt byte(s)
106: hexio_write test.db 7420 [format %02x 0xa8]
107: hexio_write test.db 10459 [format %02x 0x8d]
108:
109: sqlite3 db test.db
110:
111: set res [ catchsql {PRAGMA integrity_check} ]
112: set ans [lindex $res 1]
113:
114: list [regexp {out of order.*max larger than parent min} $ans]
115: } {1}
116:
117: do_test corruptE-2.4 {
118: db close
119: forcecopy test.bu test.db
120:
121: # insert corrupt byte(s)
122: hexio_write test.db 10233 [format %02x 0xd0]
123:
124: sqlite3 db test.db
125:
126: set res [ catchsql {PRAGMA integrity_check} ]
127: set ans [lindex $res 1]
128:
129: list [regexp {out of order.*min less than parent max} $ans]
130: } {1}
131:
132:
133: set tests [list {10233 0xd0} \
134: {941 0x42} \
135: {1028 0x53} \
136: {2041 0xd0} \
137: {2042 0x1f} \
138: {2047 0xaa} \
139: {2263 0x29} \
140: {2274 0x75} \
141: {3267 0xf2} \
142: {4104 0x2c} \
143: {5113 0x36} \
144: {10233 0x84} \
145: {10234 0x74} \
146: {10239 0x41} \
147: {10453 0x11} \
148: {11273 0x28} \
149: {11455 0x11} \
150: {11461 0xe6} \
151: {12281 0x99} \
152: {12296 0x9e} \
153: {12297 0xd7} \
154: {13303 0x53} ]
155:
156: set tc 1
157: foreach test $tests {
158: do_test corruptE-3.$tc {
159: db close
160: forcecopy test.bu test.db
161:
162: # insert corrupt byte(s)
163: hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]]
164:
165: sqlite3 db test.db
166:
167: set res [ catchsql {PRAGMA integrity_check} ]
168: set ans [lindex $res 1]
169:
170: list [regexp {out of order} $ans]
171: } {1}
172: incr tc 1
173: }
174:
175: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>