| OLD | NEW |
| 1 # 2008 Sep 10 | 1 # 2008 Sep 10 |
| 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 specifically focuses | 14 # segfault if it sees a corrupt database file. It specifically focuses |
| 15 # on loops in the B-Tree structure. A loop is formed in a B-Tree structure | 15 # on loops in the B-Tree structure. A loop is formed in a B-Tree structure |
| 16 # when there exists a page that is both an a descendent or ancestor of | 16 # when there exists a page that is both an a descendent or ancestor of |
| 17 # itself. | 17 # itself. |
| 18 # | 18 # |
| 19 # Also test that an SQLITE_CORRUPT error is returned if a B-Tree page | 19 # Also test that an SQLITE_CORRUPT error is returned if a B-Tree page |
| 20 # contains a (corrupt) reference to a page greater than the configured | 20 # contains a (corrupt) reference to a page greater than the configured |
| 21 # maximum page number. | 21 # maximum page number. |
| 22 # | 22 # |
| 23 # $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $ | 23 # $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $ |
| 24 | 24 |
| 25 set testdir [file dirname $argv0] | 25 set testdir [file dirname $argv0] |
| 26 source $testdir/tester.tcl | 26 source $testdir/tester.tcl |
| 27 | 27 |
| 28 # Do not use a codec for tests in this file, as the database file is |
| 29 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 30 # |
| 31 do_not_use_codec |
| 32 |
| 28 | 33 |
| 29 do_test corruptB-1.1 { | 34 do_test corruptB-1.1 { |
| 30 execsql { | 35 execsql { |
| 31 PRAGMA auto_vacuum = 1; | 36 PRAGMA auto_vacuum = 1; |
| 32 CREATE TABLE t1(x); | 37 CREATE TABLE t1(x); |
| 33 INSERT INTO t1 VALUES(randomblob(200)); | 38 INSERT INTO t1 VALUES(randomblob(200)); |
| 34 INSERT INTO t1 SELECT randomblob(200) FROM t1; | 39 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 35 INSERT INTO t1 SELECT randomblob(200) FROM t1; | 40 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 36 INSERT INTO t1 SELECT randomblob(200) FROM t1; | 41 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| 37 INSERT INTO t1 SELECT randomblob(200) FROM t1; | 42 INSERT INTO t1 SELECT randomblob(200) FROM t1; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 #--------------------------------------------------------------------------- | 152 #--------------------------------------------------------------------------- |
| 148 | 153 |
| 149 do_test corruptB-2.1.1 { | 154 do_test corruptB-2.1.1 { |
| 150 db close | 155 db close |
| 151 file copy -force bak.db test.db | 156 file copy -force bak.db test.db |
| 152 hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF] | 157 hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF] |
| 153 } {4} | 158 } {4} |
| 154 do_test corruptB-2.1.2 { | 159 do_test corruptB-2.1.2 { |
| 155 sqlite3 db test.db | 160 sqlite3 db test.db |
| 156 catchsql { SELECT * FROM t1 } | 161 catchsql { SELECT * FROM t1 } |
| 157 } {1 {database or disk is full}} | 162 } {1 {database disk image is malformed}} |
| 158 | 163 |
| 159 #--------------------------------------------------------------------------- | 164 #--------------------------------------------------------------------------- |
| 160 | 165 |
| 161 # Corrupt the header-size field of a database record. | 166 # Corrupt the header-size field of a database record. |
| 162 # | 167 # |
| 163 do_test corruptB-3.1.1 { | 168 do_test corruptB-3.1.1 { |
| 164 db close | 169 db close |
| 165 file copy -force bak.db test.db | 170 file copy -force bak.db test.db |
| 166 sqlite3 db test.db | 171 sqlite3 db test.db |
| 167 set v [string repeat abcdefghij 200] | 172 set v [string repeat abcdefghij 200] |
| 168 execsql { | 173 execsql { |
| 169 CREATE TABLE t2(a); | 174 CREATE TABLE t2(a); |
| 170 INSERT INTO t2 VALUES($v); | 175 INSERT INTO t2 VALUES($v); |
| 171 } | 176 } |
| 172 set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}] | 177 set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}] |
| 173 set iPage [expr ($t2_root-1)*1024] | 178 set iPage [expr ($t2_root-1)*1024] |
| 174 set iCellarray [expr $iPage + 8] | 179 set iCellarray [expr $iPage + 8] |
| 175 set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]] | 180 set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]] |
| 176 db close | 181 db close |
| 177 hexio_write test.db [expr $iPage+$iRecord+3] FF00 | 182 hexio_write test.db [expr $iPage+$iRecord+3] FF00 |
| 178 } {2} | 183 } {2} |
| 179 do_test corruptB-3.1.2 { | 184 do_test corruptB-3.1.2 { |
| 180 sqlite3 db test.db | 185 sqlite3 db test.db |
| 181 catchsql { SELECT * FROM t2 } | 186 catchsql { SELECT * FROM t2 } |
| 182 } {1 {database disk image is malformed}} | 187 } {1 {database disk image is malformed}} |
| 183 | 188 |
| 184 finish_test | 189 finish_test |
| OLD | NEW |