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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to make sure SQLite does not crash or
14 # segfault if it sees a corrupt database file. It specifically focuses
15 # on corrupt database headers.
17 # $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 # Do not use a codec for tests in this file, as the database file is
23 # manipulated directly using tcl scripts (using the [hexio_write] command).
27 # These tests deal with corrupt database files
29 database_may_be_corrupt
32 # Create a database to work with.
34 do_test corruptA-1.1 {
37 INSERT INTO t1(x) VALUES(1);
39 expr {[file size test.db]>=1024}
41 integrity_check corruptA-1.2
43 # Corrupt the file header in various ways and make sure the corruption
44 # is detected when opening the database file.
47 forcecopy test.db test.db-template
49 set unreadable_version 02
50 ifcapable wal { set unreadable_version 03 }
51 do_test corruptA-2.1 {
52 forcecopy test.db-template test.db
53 hexio_write test.db 19 $unreadable_version ;# the read format number
55 catchsql {SELECT * FROM t1}
56 } {1 {file is encrypted or is not a database}}
58 do_test corruptA-2.2 {
60 forcecopy test.db-template test.db
61 hexio_write test.db 21 41 ;# max embedded payload fraction
63 catchsql {SELECT * FROM t1}
64 } {1 {file is encrypted or is not a database}}
66 do_test corruptA-2.3 {
68 forcecopy test.db-template test.db
69 hexio_write test.db 22 1f ;# min embedded payload fraction
71 catchsql {SELECT * FROM t1}
72 } {1 {file is encrypted or is not a database}}
74 do_test corruptA-2.4 {
76 forcecopy test.db-template test.db
77 hexio_write test.db 23 21 ;# min leaf payload fraction
79 catchsql {SELECT * FROM t1}
80 } {1 {file is encrypted or is not a database}}