OLD | NEW |
| (Empty) |
1 # 2015-03-30 | |
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 # | |
12 # Corruption consisting of a database page that thinks it is a child | |
13 # of itself. | |
14 # | |
15 | |
16 set testdir [file dirname $argv0] | |
17 source $testdir/tester.tcl | |
18 set testprefix corruptJ | |
19 | |
20 if {[permutation]=="mmap"} { | |
21 finish_test | |
22 return | |
23 } | |
24 | |
25 # Do not use a codec for tests in this file, as the database file is | |
26 # manipulated directly using tcl scripts (using the [hexio_write] command). | |
27 # | |
28 do_not_use_codec | |
29 database_may_be_corrupt | |
30 | |
31 # Initialize the database. | |
32 # | |
33 do_execsql_test 1.1 { | |
34 PRAGMA page_size=1024; | |
35 PRAGMA auto_vacuum=0; | |
36 CREATE TABLE t1(a,b); | |
37 WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) | |
38 INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c; | |
39 } {} | |
40 db close | |
41 | |
42 # Corrupt the root page of the t1 table such that the left-child pointer | |
43 # for the very first cell points back to the root. Then try to DROP the | |
44 # table. The clearDatabasePage() routine should not loop. | |
45 # | |
46 do_test 1.2 { | |
47 hexio_write test.db [expr {2*1024-2}] 02 | |
48 sqlite3 db test.db | |
49 catchsql { DROP TABLE t1 } | |
50 } {1 {database disk image is malformed}} | |
51 | |
52 # Similar test using a WITHOUT ROWID table | |
53 # | |
54 do_test 2.1 { | |
55 db close | |
56 forcedelete test.db | |
57 sqlite3 db test.db | |
58 db eval { | |
59 PRAGMA page_size=1024; | |
60 PRAGMA auto_vacuum=0; | |
61 CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; | |
62 WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) | |
63 INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; | |
64 } | |
65 } {} | |
66 | |
67 # The table is three levels deep. Corrupt the left child of an intermediate | |
68 # page so that it points back to the root page. | |
69 # | |
70 do_test 2.2 { | |
71 db close | |
72 hexio_read test.db [expr {9*1024+391}] 8 | |
73 } {00000008814D0401} | |
74 do_test 2.2b { | |
75 hexio_write test.db [expr {9*1024+391}] 00000002 | |
76 sqlite3 db test.db | |
77 catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; } | |
78 } {1 {database disk image is malformed}} | |
79 | |
80 finish_test | |
OLD | NEW |