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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix corruptK
17 if {[permutation]=="mmap"} {
22 # This module uses hard-coded offsets which do not work if the reserved_bytes
24 if {[nonzero_reserved_bytes]} {finish_test; return;}
25 database_may_be_corrupt
27 # Initialize the database.
30 PRAGMA page_size=1024;
34 INSERT INTO t1 VALUES(randomblob(20));
35 INSERT INTO t1 VALUES(randomblob(100)); -- make this into a free slot
36 INSERT INTO t1 VALUES(randomblob(27)); -- this one will be corrupt
37 INSERT INTO t1 VALUES(randomblob(800));
39 DELETE FROM t1 WHERE rowid=2; -- free the 100 byte slot
44 # Corrupt the database so that the blob stored immediately before
45 # the free slot (rowid==3) has an overlarge length field. So that
46 # we can use sqlite3_blob_write() to manipulate the size field of
49 # Then use sqlite3_blob_write() to set the size of said free slot
50 # to 24 bytes (instead of the actual 100).
52 # Then use the new 24 byte slot. Leaving the in-memory version of
53 # the page with zero free slots and a large nFree value. Then try
54 # to allocate another slot to get to defragmentPage().
58 hexio_write test.db [expr 1024 + 0x360] 21
59 hexio_write test.db [expr 1024 + 0x363] [format %x [expr 31*2 + 12]]
62 set fd [db incrblob t1 x 3]
63 fconfigure $fd -translation binary -encoding binary
65 puts -nonewline $fd "\x18"
69 INSERT INTO t1 VALUES(randomblob(20));
71 do_catchsql_test 1.4 {
72 INSERT INTO t1 VALUES(randomblob(90));
73 } {1 {database disk image is malformed}}
75 #-------------------------------------------------------------------------
78 PRAGMA page_size=1024;
82 INSERT INTO t1 VALUES(randomblob(20));
83 INSERT INTO t1 VALUES(randomblob(20)); -- free this one
84 INSERT INTO t1 VALUES(randomblob(20));
85 INSERT INTO t1 VALUES(randomblob(20)); -- and this one
86 INSERT INTO t1 VALUES(randomblob(20)); -- corrupt this one.
88 DELETE FROM t1 WHERE rowid IN(2, 4);
94 hexio_write test.db [expr 1024 + 0x388] 53
95 hexio_write test.db [expr 1024 + 0x38A] 03812C
98 set fd [db incrblob t1 x 5]
99 fconfigure $fd -translation binary -encoding binary
102 puts -nonewline $fd "\x5d"
106 do_catchsql_test 2.3 {
107 INSERT INTO t1 VALUES(randomblob(900));
108 } {1 {database disk image is malformed}}