| OLD | NEW |
| 1 # 2010 February 18 | 1 # 2010 February 18 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| 11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
| 12 # | 12 # |
| 13 # This file implements tests to make sure SQLite does not crash or | 13 # This file implements tests to make sure SQLite does not crash or |
| 14 # segfault if it sees a corrupt database file. It specifcally | 14 # segfault if it sees a corrupt database file. It specifcally |
| 15 # focuses on rowid order corruption. | 15 # focuses on rowid order corruption. |
| 16 # | 16 # |
| 17 # $Id: corruptE.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ | 17 # $Id: corruptE.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ |
| 18 | 18 |
| 19 catch {file delete -force test.db test.db-journal test.bu} | |
| 20 | |
| 21 set testdir [file dirname $argv0] | 19 set testdir [file dirname $argv0] |
| 22 source $testdir/tester.tcl | 20 source $testdir/tester.tcl |
| 23 | 21 |
| 24 # Do not use a codec for tests in this file, as the database file is | 22 # Do not use a codec for tests in this file, as the database file is |
| 25 # manipulated directly using tcl scripts (using the [hexio_write] command). | 23 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 26 # | 24 # |
| 27 do_not_use_codec | 25 do_not_use_codec |
| 28 | 26 |
| 27 # These tests deal with corrupt database files |
| 28 # |
| 29 database_may_be_corrupt |
| 30 |
| 29 # Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on. | 31 # Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on. |
| 30 # | 32 # |
| 31 ifcapable oversize_cell_check { | 33 ifcapable oversize_cell_check { |
| 32 finish_test | 34 finish_test |
| 33 return | 35 return |
| 34 } | 36 } |
| 35 | 37 |
| 36 # Construct a compact, dense database for testing. | 38 # Construct a compact, dense database for testing. |
| 37 # | 39 # |
| 38 do_test corruptE-1.1 { | 40 do_test corruptE-1.1 { |
| 39 execsql { | 41 execsql { |
| 40 PRAGMA auto_vacuum = 0; | 42 PRAGMA auto_vacuum = 0; |
| 41 PRAGMA legacy_file_format=1; | 43 PRAGMA legacy_file_format=1; |
| 42 BEGIN; | 44 BEGIN; |
| 43 CREATE TABLE t1(x,y); | 45 CREATE TABLE t1(x,y); |
| 44 INSERT INTO t1 VALUES(1,1); | 46 INSERT INTO t1 VALUES(1,1); |
| 45 INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; | 47 INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; |
| 46 INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; | 48 INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; |
| 47 INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; | 49 INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; |
| 48 INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; | 50 INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; |
| 49 INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; | 51 INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; |
| 50 INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; | 52 INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; |
| 51 INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1; | 53 INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1; |
| 52 INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1; | 54 INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1; |
| 53 CREATE INDEX t1i1 ON t1(x); | 55 CREATE INDEX t1i1 ON t1(x); |
| 54 CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0; | 56 CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0 ORDER BY rowid; |
| 55 COMMIT; | 57 COMMIT; |
| 56 } | 58 } |
| 57 } {} | 59 } {} |
| 58 | 60 |
| 59 ifcapable {integrityck} { | 61 ifcapable {integrityck} { |
| 60 integrity_check corruptE-1.2 | 62 integrity_check corruptE-1.2 |
| 61 } | 63 } |
| 62 | 64 |
| 63 # Copy file $from into $to | |
| 64 # | |
| 65 proc copy_file {from to} { | |
| 66 file copy -force $from $to | |
| 67 } | |
| 68 | |
| 69 # Setup for the tests. Make a backup copy of the good database in test.bu. | 65 # Setup for the tests. Make a backup copy of the good database in test.bu. |
| 70 # | 66 # |
| 71 db close | 67 db close |
| 72 copy_file test.db test.bu | 68 forcecopy test.db test.bu |
| 73 sqlite3 db test.db | 69 sqlite3 db test.db |
| 74 set fsize [file size test.db] | 70 set fsize [file size test.db] |
| 75 | 71 |
| 76 | 72 |
| 77 do_test corruptE-2.1 { | 73 do_test corruptE-2.1 { |
| 78 db close | 74 db close |
| 79 copy_file test.bu test.db | 75 forcecopy test.bu test.db |
| 80 | 76 |
| 81 # insert corrupt byte(s) | 77 # insert corrupt byte(s) |
| 82 hexio_write test.db 2041 [format %02x 0x2e] | 78 hexio_write test.db 2041 [format %02x 0x2e] |
| 83 | 79 |
| 84 sqlite3 db test.db | 80 sqlite3 db test.db |
| 85 | 81 |
| 86 set res [ catchsql {PRAGMA integrity_check} ] | 82 set res [ catchsql {PRAGMA integrity_check} ] |
| 87 set ans [lindex $res 1] | 83 set ans [lindex $res 1] |
| 88 | 84 |
| 89 list [regexp {out of order.*previous was} $ans] \ | 85 list [regexp {out of order.*previous was} $ans] \ |
| 90 [regexp {out of order.*max larger than parent max} $ans] | 86 [regexp {out of order.*max larger than parent max} $ans] |
| 91 } {1 1} | 87 } {1 1} |
| 92 | 88 |
| 93 do_test corruptE-2.2 { | 89 do_test corruptE-2.2 { |
| 94 db close | 90 db close |
| 95 copy_file test.bu test.db | 91 forcecopy test.bu test.db |
| 96 | 92 |
| 97 # insert corrupt byte(s) | 93 # insert corrupt byte(s) |
| 98 hexio_write test.db 2047 [format %02x 0x84] | 94 hexio_write test.db 2047 [format %02x 0x84] |
| 99 | 95 |
| 100 sqlite3 db test.db | 96 sqlite3 db test.db |
| 101 | 97 |
| 102 set res [ catchsql {PRAGMA integrity_check} ] | 98 set res [ catchsql {PRAGMA integrity_check} ] |
| 103 set ans [lindex $res 1] | 99 set ans [lindex $res 1] |
| 104 | 100 |
| 105 list [regexp {out of order.*previous was} $ans] \ | 101 list [regexp {out of order.*previous was} $ans] \ |
| 106 [regexp {out of order.*min less than parent min} $ans] | 102 [regexp {out of order.*min less than parent min} $ans] |
| 107 } {1 1} | 103 } {1 1} |
| 108 | 104 |
| 109 do_test corruptE-2.3 { | 105 do_test corruptE-2.3 { |
| 110 db close | 106 db close |
| 111 copy_file test.bu test.db | 107 forcecopy test.bu test.db |
| 112 | 108 |
| 113 # insert corrupt byte(s) | 109 # insert corrupt byte(s) |
| 114 hexio_write test.db 7420 [format %02x 0xa8] | 110 hexio_write test.db 7420 [format %02x 0xa8] |
| 115 hexio_write test.db 10459 [format %02x 0x8d] | 111 hexio_write test.db 10459 [format %02x 0x8d] |
| 116 | 112 |
| 117 sqlite3 db test.db | 113 sqlite3 db test.db |
| 118 | 114 |
| 119 set res [ catchsql {PRAGMA integrity_check} ] | 115 set res [ catchsql {PRAGMA integrity_check} ] |
| 120 set ans [lindex $res 1] | 116 set ans [lindex $res 1] |
| 121 | 117 |
| 122 list [regexp {out of order.*max larger than parent min} $ans] | 118 list [regexp {out of order.*max larger than parent min} $ans] |
| 123 } {1} | 119 } {1} |
| 124 | 120 |
| 125 do_test corruptE-2.4 { | 121 do_test corruptE-2.4 { |
| 126 db close | 122 db close |
| 127 copy_file test.bu test.db | 123 forcecopy test.bu test.db |
| 128 | 124 |
| 129 # insert corrupt byte(s) | 125 # insert corrupt byte(s) |
| 130 hexio_write test.db 10233 [format %02x 0xd0] | 126 hexio_write test.db 10233 [format %02x 0xd0] |
| 131 | 127 |
| 132 sqlite3 db test.db | 128 sqlite3 db test.db |
| 133 | 129 |
| 134 set res [ catchsql {PRAGMA integrity_check} ] | 130 set res [ catchsql {PRAGMA integrity_check} ] |
| 135 set ans [lindex $res 1] | 131 set ans [lindex $res 1] |
| 136 | 132 |
| 137 list [regexp {out of order.*min less than parent max} $ans] | 133 list [regexp {out of order.*min less than parent max} $ans] |
| (...skipping 20 matching lines...) Expand all Loading... |
| 158 {11461 0xe6} \ | 154 {11461 0xe6} \ |
| 159 {12281 0x99} \ | 155 {12281 0x99} \ |
| 160 {12296 0x9e} \ | 156 {12296 0x9e} \ |
| 161 {12297 0xd7} \ | 157 {12297 0xd7} \ |
| 162 {13303 0x53} ] | 158 {13303 0x53} ] |
| 163 | 159 |
| 164 set tc 1 | 160 set tc 1 |
| 165 foreach test $tests { | 161 foreach test $tests { |
| 166 do_test corruptE-3.$tc { | 162 do_test corruptE-3.$tc { |
| 167 db close | 163 db close |
| 168 copy_file test.bu test.db | 164 forcecopy test.bu test.db |
| 169 | 165 |
| 170 # insert corrupt byte(s) | 166 # insert corrupt byte(s) |
| 171 hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] | 167 hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] |
| 172 | 168 |
| 173 sqlite3 db test.db | 169 sqlite3 db test.db |
| 174 | 170 |
| 175 set res [ catchsql {PRAGMA integrity_check} ] | 171 set res [ catchsql {PRAGMA integrity_check} ] |
| 176 set ans [lindex $res 1] | 172 set ans [lindex $res 1] |
| 177 | 173 |
| 178 list [regexp {out of order} $ans] | 174 list [regexp {out of order} $ans] |
| 179 } {1} | 175 } {1} |
| 180 incr tc 1 | 176 incr tc 1 |
| 181 } | 177 } |
| 182 | 178 |
| 183 finish_test | 179 finish_test |
| OLD | NEW |