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

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

Issue 6990047: Import SQLite 3.7.6.3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/src/test/conflict.test ('k') | third_party/sqlite/src/test/corrupt2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2004 August 30 1 # 2004 August 30 {}
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 #***********************************************************************
11 # This file implements regression tests for SQLite library. 11 # This file implements regression tests for SQLite library.
12 # 12 #
13 # This file implements tests to make sure SQLite does not crash or 13 # This file implements tests to make sure SQLite does not crash or
14 # segfault if it sees a corrupt database file. 14 # segfault if it sees a corrupt database file.
15 # 15 #
16 # $Id: corrupt.test,v 1.12 2009/07/13 09:41:45 danielk1977 Exp $ 16 # $Id: corrupt.test,v 1.12 2009/07/13 09:41:45 danielk1977 Exp $
17 17
18 catch {file delete -force test.db test.db-journal test.bu} 18 catch {file delete -force test.db test.db-journal test.bu}
19 19
20 set testdir [file dirname $argv0] 20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl 21 source $testdir/tester.tcl
22 22
23 # Do not use a codec for tests in this file, as the database file is
24 # manipulated directly using tcl scripts (using the [hexio_write] command).
25 #
26 do_not_use_codec
27
23 # Construct a large database for testing. 28 # Construct a large database for testing.
24 # 29 #
25 do_test corrupt-1.1 { 30 do_test corrupt-1.1 {
26 execsql { 31 execsql {
27 BEGIN; 32 BEGIN;
28 CREATE TABLE t1(x); 33 CREATE TABLE t1(x);
29 INSERT INTO t1 VALUES(randstr(100,100)); 34 INSERT INTO t1 VALUES(randstr(100,100));
30 INSERT INTO t1 VALUES(randstr(90,90)); 35 INSERT INTO t1 VALUES(randstr(90,90));
31 INSERT INTO t1 VALUES(randstr(80,80)); 36 INSERT INTO t1 VALUES(randstr(80,80));
32 INSERT INTO t1 SELECT x || randstr(5,5) FROM t1; 37 INSERT INTO t1 SELECT x || randstr(5,5) FROM t1;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 set rootpage [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}] 255 set rootpage [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}]
251 db close 256 db close
252 257
253 set offset [expr ($rootpage * 1024)-14+2] 258 set offset [expr ($rootpage * 1024)-14+2]
254 hexio_write test.db $offset 00FF 259 hexio_write test.db $offset 00FF
255 sqlite3 db test.db 260 sqlite3 db test.db
256 261
257 catchsql { INSERT INTO t1 VALUES( randomblob(10) ) } 262 catchsql { INSERT INTO t1 VALUES( randomblob(10) ) }
258 } {1 {database disk image is malformed}} 263 } {1 {database disk image is malformed}}
259 264
265 ifcapable oversize_cell_check {
266 db close
267 file delete -force test.db test.db-journal
268 sqlite3 db test.db
269 execsql {
270 PRAGMA page_size = 1024; CREATE TABLE t1(x);
271 }
272
273 do_test corrupt-7.1 {
274 for {set i 0} {$i < 39} {incr i} {
275 execsql {
276 INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A');
277 }
278 }
279 } {}
280 db close
281
282 # Corrupt the root page of table t1 so that the first offset in the
283 # cell-offset array points to the data for the SQL blob associated with
284 # record (rowid=10). The root page still passes the checks in btreeInitPage(),
285 # because the start of said blob looks like the start of a legitimate
286 # page cell.
287 #
288 # Test case cc-2 overwrites the blob so that it no longer looks like a
289 # real cell. But, by the time it is overwritten, btreeInitPage() has already
290 # initialized the root page, so no corruption is detected.
291 #
292 # Test case cc-3 inserts an extra record into t1, forcing balance-deeper
293 # to run. After copying the contents of the root page to the new child,
294 # btreeInitPage() is called on the child. This time, it detects corruption
295 # (because the start of the blob associated with the (rowid=10) record
296 # no longer looks like a real cell). At one point the code assumed that
297 # detecting corruption was not possible at that point, and an assert() failed.
298 #
299 set fd [open test.db r+]
300 fconfigure $fd -translation binary -encoding binary
301 seek $fd [expr 1024+8]
302 puts -nonewline $fd "\x03\x14"
303 close $fd
304
305 sqlite3 db test.db
306 do_test corrupt-7.2 {
307 execsql {
308 UPDATE t1 SET x = X'870400020003000400050006000700080009000A'
309 WHERE rowid = 10;
310 }
311 } {}
312 do_test corrupt-7.3 {
313 catchsql {
314 INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A');
315 }
316 } {1 {database disk image is malformed}}
317 }
318
319 db close
320 file delete -force test.db test.db-journal
321 do_test corrupt-8.1 {
322 sqlite3 db test.db
323 execsql {
324 PRAGMA page_size = 1024;
325 PRAGMA secure_delete = on;
326 PRAGMA auto_vacuum = 0;
327 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
328 INSERT INTO t1 VALUES(5, randomblob(1900));
329 }
330
331 hexio_write test.db 2044 [hexio_render_int32 2]
332 hexio_write test.db 24 [hexio_render_int32 45]
333
334 catchsql { INSERT OR REPLACE INTO t1 VALUES(5, randomblob(1900)) }
335 } {1 {database disk image is malformed}}
336
337 db close
338 file delete -force test.db test.db-journal
339 do_test corrupt-8.2 {
340 sqlite3 db test.db
341 execsql {
342 PRAGMA page_size = 1024;
343 PRAGMA secure_delete = on;
344 PRAGMA auto_vacuum = 0;
345 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
346 INSERT INTO t1 VALUES(5, randomblob(900));
347 INSERT INTO t1 VALUES(6, randomblob(900));
348 }
349
350 hexio_write test.db 2047 FF
351 hexio_write test.db 24 [hexio_render_int32 45]
352
353 catchsql { INSERT INTO t1 VALUES(4, randomblob(1900)) }
354 } {1 {database disk image is malformed}}
355
260 finish_test 356 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/conflict.test ('k') | third_party/sqlite/src/test/corrupt2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698