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 corruptG
17 # This module uses hard-coded offsets which do not work if the reserved_bytes
19 if {[nonzero_reserved_bytes]} {finish_test; return;}
21 # These tests deal with corrupt database files
23 database_may_be_corrupt
25 # Create a simple database with a single entry. Then corrupt the
26 # header-size varint on the index payload so that it maps into a
27 # negative number. Try to use the database.
32 CREATE TABLE t1(a,b,c);
33 INSERT INTO t1(rowid,a,b,c) VALUES(52,'abc','xyz','123');
34 CREATE INDEX t1abc ON t1(a,b,c);
37 set idxroot [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1abc'}]
41 hexio_write test.db [expr {$idxroot*512 - 15}] 888080807f
44 # Try to use the file.
47 SELECT c FROM t1 WHERE a>'abc';
49 } {1 {database disk image is malformed}}
52 PRAGMA integrity_check
54 } {1 {database disk image is malformed}}
57 SELECT c FROM t1 ORDER BY a;
59 } {1 {database disk image is malformed}}
61 # Corrupt the same file in a slightly different way. Make the record header
62 # sane, but corrupt one of the serial_type value to indicate a huge payload
63 # such that the payload begins in allocated space but overflows the buffer.
66 hexio_write test.db [expr {$idxroot*512-15}] 0513ff7f01
71 SELECT rowid FROM t1 WHERE a='abc' and b='xyz123456789XYZ';
73 } {1 {database disk image is malformed}}