Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: third_party/sqlite/src/test/corruptB.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2008 Sep 10 1 # 2008 Sep 10
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
(...skipping 12 matching lines...) Expand all
23 # $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $ 23 # $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $
24 24
25 set testdir [file dirname $argv0] 25 set testdir [file dirname $argv0]
26 source $testdir/tester.tcl 26 source $testdir/tester.tcl
27 27
28 # Do not use a codec for tests in this file, as the database file is 28 # Do not use a codec for tests in this file, as the database file is
29 # manipulated directly using tcl scripts (using the [hexio_write] command). 29 # manipulated directly using tcl scripts (using the [hexio_write] command).
30 # 30 #
31 do_not_use_codec 31 do_not_use_codec
32 32
33 # These tests deal with corrupt database files
34 #
35 database_may_be_corrupt
36
33 37
34 do_test corruptB-1.1 { 38 do_test corruptB-1.1 {
35 execsql { 39 execsql {
36 PRAGMA auto_vacuum = 1; 40 PRAGMA auto_vacuum = 1;
37 CREATE TABLE t1(x); 41 CREATE TABLE t1(x);
38 INSERT INTO t1 VALUES(randomblob(200)); 42 INSERT INTO t1 VALUES(randomblob(200));
39 INSERT INTO t1 SELECT randomblob(200) FROM t1; 43 INSERT INTO t1 SELECT randomblob(200) FROM t1;
40 INSERT INTO t1 SELECT randomblob(200) FROM t1; 44 INSERT INTO t1 SELECT randomblob(200) FROM t1;
41 INSERT INTO t1 SELECT randomblob(200) FROM t1; 45 INSERT INTO t1 SELECT randomblob(200) FROM t1;
42 INSERT INTO t1 SELECT randomblob(200) FROM t1; 46 INSERT INTO t1 SELECT randomblob(200) FROM t1;
43 INSERT INTO t1 SELECT randomblob(200) FROM t1; 47 INSERT INTO t1 SELECT randomblob(200) FROM t1;
44 } 48 }
45 expr {[file size test.db] > (1024*9)} 49 expr {[file size test.db] > (1024*9)}
46 } {1} 50 } {1}
47 integrity_check corruptB-1.2 51 integrity_check corruptB-1.2
48 52
49 file copy -force test.db bak.db 53 forcecopy test.db bak.db
50 54
51 # Set the right-child of a B-Tree rootpage to refer to the root-page itself. 55 # Set the right-child of a B-Tree rootpage to refer to the root-page itself.
52 # 56 #
53 do_test corruptB-1.3.1 { 57 do_test corruptB-1.3.1 {
54 set ::root [execsql {SELECT rootpage FROM sqlite_master}] 58 set ::root [execsql {SELECT rootpage FROM sqlite_master}]
55 set ::offset [expr {($::root-1)*1024}] 59 set ::offset [expr {($::root-1)*1024}]
56 hexio_write test.db [expr $offset+8] [hexio_render_int32 $::root] 60 hexio_write test.db [expr $offset+8] [hexio_render_int32 $::root]
57 } {4} 61 } {4}
58 do_test corruptB-1.3.2 { 62 do_test corruptB-1.3.2 {
59 sqlite3 db test.db 63 sqlite3 db test.db
60 catchsql { SELECT * FROM t1 } 64 catchsql { SELECT * FROM t1 }
61 } {1 {database disk image is malformed}} 65 } {1 {database disk image is malformed}}
62 66
63 # Set the left-child of a cell in a B-Tree rootpage to refer to the 67 # Set the left-child of a cell in a B-Tree rootpage to refer to the
64 # root-page itself. 68 # root-page itself.
65 # 69 #
66 do_test corruptB-1.4.1 { 70 do_test corruptB-1.4.1 {
67 db close 71 db close
68 file copy -force bak.db test.db 72 forcecopy bak.db test.db
69 set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] 73 set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]]
70 hexio_write test.db [expr $offset+$cell_offset] [hexio_render_int32 $::root] 74 hexio_write test.db [expr $offset+$cell_offset] [hexio_render_int32 $::root]
71 } {4} 75 } {4}
72 do_test corruptB-1.4.2 { 76 do_test corruptB-1.4.2 {
73 sqlite3 db test.db 77 sqlite3 db test.db
74 catchsql { SELECT * FROM t1 } 78 catchsql { SELECT * FROM t1 }
75 } {1 {database disk image is malformed}} 79 } {1 {database disk image is malformed}}
76 80
77 # Now grow the table B-Tree so that it is more than 2 levels high. 81 # Now grow the table B-Tree so that it is more than 2 levels high.
78 # 82 #
79 do_test corruptB-1.5.1 { 83 do_test corruptB-1.5.1 {
80 db close 84 db close
81 file copy -force bak.db test.db 85 forcecopy bak.db test.db
82 sqlite3 db test.db 86 sqlite3 db test.db
83 execsql { 87 execsql {
84 INSERT INTO t1 SELECT randomblob(200) FROM t1; 88 INSERT INTO t1 SELECT randomblob(200) FROM t1;
85 INSERT INTO t1 SELECT randomblob(200) FROM t1; 89 INSERT INTO t1 SELECT randomblob(200) FROM t1;
86 INSERT INTO t1 SELECT randomblob(200) FROM t1; 90 INSERT INTO t1 SELECT randomblob(200) FROM t1;
87 INSERT INTO t1 SELECT randomblob(200) FROM t1; 91 INSERT INTO t1 SELECT randomblob(200) FROM t1;
88 INSERT INTO t1 SELECT randomblob(200) FROM t1; 92 INSERT INTO t1 SELECT randomblob(200) FROM t1;
89 INSERT INTO t1 SELECT randomblob(200) FROM t1; 93 INSERT INTO t1 SELECT randomblob(200) FROM t1;
90 INSERT INTO t1 SELECT randomblob(200) FROM t1; 94 INSERT INTO t1 SELECT randomblob(200) FROM t1;
91 } 95 }
92 } {} 96 } {}
93 97
94 file copy -force test.db bak.db 98 forcecopy test.db bak.db
95 99
96 # Set the right-child pointer of the right-child of the root page to point 100 # Set the right-child pointer of the right-child of the root page to point
97 # back to the root page. 101 # back to the root page.
98 # 102 #
99 do_test corruptB-1.6.1 { 103 do_test corruptB-1.6.1 {
100 db close 104 db close
101 set iRightChild [hexio_get_int [hexio_read test.db [expr $offset+8] 4]] 105 set iRightChild [hexio_get_int [hexio_read test.db [expr $offset+8] 4]]
102 set c_offset [expr ($iRightChild-1)*1024] 106 set c_offset [expr ($iRightChild-1)*1024]
103 hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] 107 hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root]
104 } {4} 108 } {4}
105 do_test corruptB-1.6.2 { 109 do_test corruptB-1.6.2 {
106 sqlite3 db test.db 110 sqlite3 db test.db
107 catchsql { SELECT * FROM t1 } 111 catchsql { SELECT * FROM t1 }
108 } {1 {database disk image is malformed}} 112 } {1 {database disk image is malformed}}
109 113
110 # Set the left-child pointer of a cell of the right-child of the root page to 114 # Set the left-child pointer of a cell of the right-child of the root page to
111 # point back to the root page. 115 # point back to the root page.
112 # 116 #
113 do_test corruptB-1.7.1 { 117 do_test corruptB-1.7.1 {
114 db close 118 db close
115 file copy -force bak.db test.db 119 forcecopy bak.db test.db
116 set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] 120 set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]]
117 hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] 121 hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root]
118 } {4} 122 } {4}
119 do_test corruptB-1.7.2 { 123 do_test corruptB-1.7.2 {
120 sqlite3 db test.db 124 sqlite3 db test.db
121 catchsql { SELECT * FROM t1 } 125 catchsql { SELECT * FROM t1 }
122 } {1 {database disk image is malformed}} 126 } {1 {database disk image is malformed}}
123 127
124 do_test corruptB-1.8.1 { 128 do_test corruptB-1.8.1 {
125 db close 129 db close
126 set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] 130 set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]]
127 set iLeftChild [ 131 set iLeftChild [
128 hexio_get_int [hexio_read test.db [expr $offset+$cell_offset] 4] 132 hexio_get_int [hexio_read test.db [expr $offset+$cell_offset] 4]
129 ] 133 ]
130 set c_offset [expr ($iLeftChild-1)*1024] 134 set c_offset [expr ($iLeftChild-1)*1024]
131 hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] 135 hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root]
132 } {4} 136 } {4}
133 do_test corruptB-1.8.2 { 137 do_test corruptB-1.8.2 {
134 sqlite3 db test.db 138 sqlite3 db test.db
135 catchsql { SELECT * FROM t1 } 139 catchsql { SELECT * FROM t1 }
136 } {1 {database disk image is malformed}} 140 } {1 {database disk image is malformed}}
137 141
138 # Set the left-child pointer of a cell of the right-child of the root page to 142 # Set the left-child pointer of a cell of the right-child of the root page to
139 # point back to the root page. 143 # point back to the root page.
140 # 144 #
141 do_test corruptB-1.9.1 { 145 do_test corruptB-1.9.1 {
142 db close 146 db close
143 file copy -force bak.db test.db 147 forcecopy bak.db test.db
144 set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] 148 set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]]
145 hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] 149 hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root]
146 } {4} 150 } {4}
147 do_test corruptB-1.9.2 { 151 do_test corruptB-1.9.2 {
148 sqlite3 db test.db 152 sqlite3 db test.db
149 catchsql { SELECT * FROM t1 } 153 catchsql { SELECT * FROM t1 }
150 } {1 {database disk image is malformed}} 154 } {1 {database disk image is malformed}}
151 155
152 #--------------------------------------------------------------------------- 156 #---------------------------------------------------------------------------
153 157
154 do_test corruptB-2.1.1 { 158 do_test corruptB-2.1.1 {
155 db close 159 db close
156 file copy -force bak.db test.db 160 forcecopy bak.db test.db
157 hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF] 161 hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF]
158 } {4} 162 } {4}
159 do_test corruptB-2.1.2 { 163 do_test corruptB-2.1.2 {
160 sqlite3 db test.db 164 sqlite3 db test.db
161 catchsql { SELECT * FROM t1 } 165 catchsql { SELECT * FROM t1 }
162 } {1 {database disk image is malformed}} 166 } {1 {database disk image is malformed}}
163 167
164 #--------------------------------------------------------------------------- 168 #---------------------------------------------------------------------------
165 169
166 # Corrupt the header-size field of a database record. 170 # Corrupt the header-size field of a database record.
167 # 171 #
168 do_test corruptB-3.1.1 { 172 do_test corruptB-3.1.1 {
169 db close 173 db close
170 file copy -force bak.db test.db 174 forcecopy bak.db test.db
171 sqlite3 db test.db 175 sqlite3 db test.db
172 set v [string repeat abcdefghij 200] 176 set v [string repeat abcdefghij 200]
173 execsql { 177 execsql {
174 CREATE TABLE t2(a); 178 CREATE TABLE t2(a);
175 INSERT INTO t2 VALUES($v); 179 INSERT INTO t2 VALUES($v);
176 } 180 }
177 set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}] 181 set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}]
178 set iPage [expr ($t2_root-1)*1024] 182 set iPage [expr ($t2_root-1)*1024]
179 set iCellarray [expr $iPage + 8] 183 set iCellarray [expr $iPage + 8]
180 set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]] 184 set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]]
181 db close 185 db close
182 hexio_write test.db [expr $iPage+$iRecord+3] FF00 186 hexio_write test.db [expr $iPage+$iRecord+3] FF00
183 } {2} 187 } {2}
184 do_test corruptB-3.1.2 { 188 do_test corruptB-3.1.2 {
185 sqlite3 db test.db 189 sqlite3 db test.db
186 catchsql { SELECT * FROM t2 } 190 catchsql { SELECT * FROM t2 }
187 } {1 {database disk image is malformed}} 191 } {1 {database disk image is malformed}}
188 192
189 finish_test 193 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698