| 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 $ | |
| 18 | 17 |
| 19 set testdir [file dirname $argv0] | 18 set testdir [file dirname $argv0] |
| 20 source $testdir/tester.tcl | 19 source $testdir/tester.tcl |
| 21 | 20 |
| 22 # Do not use a codec for tests in this file, as the database file is | 21 # 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). | 22 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 24 # | 23 # |
| 25 do_not_use_codec | 24 do_not_use_codec |
| 26 | 25 |
| 27 # These tests deal with corrupt database files | 26 # These tests deal with corrupt database files |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 71 |
| 73 do_test corruptE-2.1 { | 72 do_test corruptE-2.1 { |
| 74 db close | 73 db close |
| 75 forcecopy test.bu test.db | 74 forcecopy test.bu test.db |
| 76 | 75 |
| 77 # insert corrupt byte(s) | 76 # insert corrupt byte(s) |
| 78 hexio_write test.db 2041 [format %02x 0x2e] | 77 hexio_write test.db 2041 [format %02x 0x2e] |
| 79 | 78 |
| 80 sqlite3 db test.db | 79 sqlite3 db test.db |
| 81 | 80 |
| 82 set res [ catchsql {PRAGMA integrity_check} ] | 81 catchsql {PRAGMA integrity_check} |
| 83 set ans [lindex $res 1] | 82 } {/ out of order/} |
| 84 | |
| 85 list [regexp {out of order.*previous was} $ans] \ | |
| 86 [regexp {out of order.*max larger than parent max} $ans] | |
| 87 } {1 1} | |
| 88 | 83 |
| 89 do_test corruptE-2.2 { | 84 do_test corruptE-2.2 { |
| 90 db close | 85 db close |
| 91 forcecopy test.bu test.db | 86 forcecopy test.bu test.db |
| 92 | 87 |
| 93 # insert corrupt byte(s) | 88 # insert corrupt byte(s) |
| 94 hexio_write test.db 2047 [format %02x 0x84] | 89 hexio_write test.db 2047 [format %02x 0x84] |
| 95 | 90 |
| 96 sqlite3 db test.db | 91 sqlite3 db test.db |
| 97 | 92 |
| 98 set res [ catchsql {PRAGMA integrity_check} ] | 93 catchsql {PRAGMA integrity_check} |
| 99 set ans [lindex $res 1] | 94 } {/ Extends off end of page/} |
| 100 | |
| 101 list [regexp {out of order.*previous was} $ans] \ | |
| 102 [regexp {out of order.*min less than parent min} $ans] | |
| 103 } {1 1} | |
| 104 | 95 |
| 105 do_test corruptE-2.3 { | 96 do_test corruptE-2.3 { |
| 106 db close | 97 db close |
| 107 forcecopy test.bu test.db | 98 forcecopy test.bu test.db |
| 108 | 99 |
| 109 # insert corrupt byte(s) | 100 # insert corrupt byte(s) |
| 110 hexio_write test.db 7420 [format %02x 0xa8] | 101 hexio_write test.db 7420 [format %02x 0xa8] |
| 111 hexio_write test.db 10459 [format %02x 0x8d] | 102 hexio_write test.db 10459 [format %02x 0x8d] |
| 112 | 103 |
| 113 sqlite3 db test.db | 104 sqlite3 db test.db |
| 114 | 105 |
| 115 set res [ catchsql {PRAGMA integrity_check} ] | 106 catchsql {PRAGMA integrity_check} |
| 116 set ans [lindex $res 1] | 107 } {/out of order/} |
| 117 | |
| 118 list [regexp {out of order.*max larger than parent min} $ans] | |
| 119 } {1} | |
| 120 | 108 |
| 121 do_test corruptE-2.4 { | 109 do_test corruptE-2.4 { |
| 122 db close | 110 db close |
| 123 forcecopy test.bu test.db | 111 forcecopy test.bu test.db |
| 124 | 112 |
| 125 # insert corrupt byte(s) | 113 # insert corrupt byte(s) |
| 126 hexio_write test.db 10233 [format %02x 0xd0] | 114 hexio_write test.db 10233 [format %02x 0xd0] |
| 127 | 115 |
| 128 sqlite3 db test.db | 116 sqlite3 db test.db |
| 129 | 117 |
| 130 set res [ catchsql {PRAGMA integrity_check} ] | 118 catchsql {PRAGMA integrity_check} |
| 131 set ans [lindex $res 1] | 119 } {/out of order/} |
| 132 | |
| 133 list [regexp {out of order.*min less than parent max} $ans] | |
| 134 } {1} | |
| 135 | 120 |
| 136 | 121 |
| 137 set tests [list {10233 0xd0} \ | 122 set tests [list {10233 0xd0} \ |
| 138 {941 0x42} \ | 123 {941 0x42} \ |
| 139 {1028 0x53} \ | |
| 140 {2041 0xd0} \ | 124 {2041 0xd0} \ |
| 141 {2042 0x1f} \ | 125 {2042 0x1f} \ |
| 142 {2047 0xaa} \ | |
| 143 {2263 0x29} \ | |
| 144 {2274 0x75} \ | 126 {2274 0x75} \ |
| 145 {3267 0xf2} \ | 127 {3267 0xf2} \ |
| 146 {4104 0x2c} \ | |
| 147 {5113 0x36} \ | 128 {5113 0x36} \ |
| 148 {10233 0x84} \ | 129 {10233 0x84} \ |
| 149 {10234 0x74} \ | 130 {10234 0x74} \ |
| 150 {10239 0x41} \ | 131 {10239 0x41} \ |
| 151 {10453 0x11} \ | |
| 152 {11273 0x28} \ | 132 {11273 0x28} \ |
| 153 {11455 0x11} \ | |
| 154 {11461 0xe6} \ | 133 {11461 0xe6} \ |
| 155 {12281 0x99} \ | |
| 156 {12296 0x9e} \ | |
| 157 {12297 0xd7} \ | 134 {12297 0xd7} \ |
| 158 {13303 0x53} ] | 135 {13303 0x53} ] |
| 159 | 136 |
| 160 set tc 1 | 137 set tc 1 |
| 161 foreach test $tests { | 138 foreach test $tests { |
| 162 do_test corruptE-3.$tc { | 139 do_test corruptE-3.$tc { |
| 163 db close | 140 db close |
| 164 forcecopy test.bu test.db | 141 forcecopy test.bu test.db |
| 165 | 142 |
| 166 # insert corrupt byte(s) | 143 # insert corrupt byte(s) |
| 167 hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] | 144 hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] |
| 168 | 145 |
| 169 sqlite3 db test.db | 146 sqlite3 db test.db |
| 170 | 147 |
| 171 set res [ catchsql {PRAGMA integrity_check} ] | 148 catchsql {PRAGMA integrity_check} |
| 172 set ans [lindex $res 1] | 149 } {/out of order/} |
| 173 | |
| 174 list [regexp {out of order} $ans] | |
| 175 } {1} | |
| 176 incr tc 1 | 150 incr tc 1 |
| 177 } | 151 } |
| 178 | 152 |
| 179 finish_test | 153 finish_test |
| OLD | NEW |