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 #***********************************************************************
12 # Corruption consisting of a database page that thinks it is a child
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix corruptJ
20 if {[permutation]=="mmap"} {
25 # This module uses hard-coded offsets which do not work if the reserved_bytes
27 if {[nonzero_reserved_bytes]} {finish_test; return;}
29 database_may_be_corrupt
31 # Initialize the database.
34 PRAGMA page_size=1024;
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;
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.
47 hexio_write test.db [expr {2*1024-2}] 02
49 catchsql { DROP TABLE t1 }
50 } {1 {database disk image is malformed}}
52 # Similar test using a WITHOUT ROWID table
59 PRAGMA page_size=1024;
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;
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.
72 hexio_read test.db [expr {9*1024+391}] 8
75 hexio_write test.db [expr {9*1024+391}] 00000002
77 catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; }
78 } {1 {database disk image is malformed}}