OLD | NEW |
1 # 2009 June 3 | 1 # 2009 June 3 |
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 # | 11 # |
12 # $Id: corruptD.test,v 1.2 2009/06/05 17:09:12 drh Exp $ | 12 # $Id: corruptD.test,v 1.2 2009/06/05 17:09:12 drh Exp $ |
13 | 13 |
14 set testdir [file dirname $argv0] | 14 set testdir [file dirname $argv0] |
15 source $testdir/tester.tcl | 15 source $testdir/tester.tcl |
16 | 16 |
17 # Do not use a codec for tests in this file, as the database file is | 17 # Do not use a codec for tests in this file, as the database file is |
18 # manipulated directly using tcl scripts (using the [hexio_write] command). | 18 # manipulated directly using tcl scripts (using the [hexio_write] command). |
19 # | 19 # |
20 do_not_use_codec | 20 do_not_use_codec |
21 | 21 |
| 22 # These tests deal with corrupt database files |
| 23 # |
| 24 database_may_be_corrupt |
| 25 |
22 #-------------------------------------------------------------------------- | 26 #-------------------------------------------------------------------------- |
23 # OVERVIEW | 27 # OVERVIEW |
24 # | 28 # |
25 # This test file attempts to verify that SQLite does not read past the | 29 # This test file attempts to verify that SQLite does not read past the |
26 # end of any in-memory buffers as a result of corrupted database page | 30 # end of any in-memory buffers as a result of corrupted database page |
27 # images. Usually this happens because a field within a database page | 31 # images. Usually this happens because a field within a database page |
28 # that contains an offset to some other structure within the same page | 32 # that contains an offset to some other structure within the same page |
29 # is set to too large a value. A database page contains the following | 33 # is set to too large a value. A database page contains the following |
30 # such fields: | 34 # such fields: |
31 # | 35 # |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 82 } |
79 for {set ii 1} {$ii < 50} {incr ii} { | 83 for {set ii 1} {$ii < 50} {incr ii} { |
80 execsql { INSERT INTO t1 VALUES($ii, $ii * $ii) } | 84 execsql { INSERT INTO t1 VALUES($ii, $ii * $ii) } |
81 } | 85 } |
82 execsql { | 86 execsql { |
83 DELETE FROM t1 WHERE a = 10; | 87 DELETE FROM t1 WHERE a = 10; |
84 DELETE FROM t1 WHERE a = 20; | 88 DELETE FROM t1 WHERE a = 20; |
85 DELETE FROM t1 WHERE a = 30; | 89 DELETE FROM t1 WHERE a = 30; |
86 DELETE FROM t1 WHERE a = 40; | 90 DELETE FROM t1 WHERE a = 40; |
87 } | 91 } |
88 copy_file test.db test.bu | 92 forcecopy test.db test.bu |
89 } {} | 93 } {} |
90 | 94 |
91 proc incr_change_counter {} { | 95 proc incr_change_counter {} { |
92 hexio_write test.db 24 [ | 96 hexio_write test.db 24 [ |
93 hexio_render_int32 [expr [hexio_get_int [hexio_read test.db 24 4]] + 1] | 97 hexio_render_int32 [expr [hexio_get_int [hexio_read test.db 24 4]] + 1] |
94 ] | 98 ] |
95 } | 99 } |
96 | 100 |
97 proc restore_file {} { | 101 proc restore_file {} { |
98 db close | 102 db close |
99 copy_file test.bu test.db | 103 forcecopy test.bu test.db |
100 sqlite3 db test.db | 104 sqlite3 db test.db |
101 } | 105 } |
102 | 106 |
103 #------------------------------------------------------------------------- | 107 #------------------------------------------------------------------------- |
104 # The following tests, corruptD-1.1.*, focus on the page header field | 108 # The following tests, corruptD-1.1.*, focus on the page header field |
105 # containing the offset of the first free block in a page. | 109 # containing the offset of the first free block in a page. |
106 # | 110 # |
107 do_test corruptD-1.1.1 { | 111 do_test corruptD-1.1.1 { |
108 incr_change_counter | 112 incr_change_counter |
109 hexio_write test.db [expr 1024+1] FFFF | 113 hexio_write test.db [expr 1024+1] FFFF |
110 catchsql { SELECT * FROM t1 } | 114 catchsql { SELECT * FROM t1 ORDER BY rowid } |
111 } {1 {database disk image is malformed}} | 115 } {1 {database disk image is malformed}} |
112 do_test corruptD-1.1.2 { | 116 do_test corruptD-1.1.2 { |
113 incr_change_counter | 117 incr_change_counter |
114 hexio_write test.db [expr 1024+1] [hexio_render_int32 1021] | 118 hexio_write test.db [expr 1024+1] [hexio_render_int32 1021] |
115 catchsql { SELECT * FROM t1 } | 119 catchsql { SELECT * FROM t1 ORDER BY rowid } |
116 } {1 {database disk image is malformed}} | 120 } {1 {database disk image is malformed}} |
117 | 121 |
118 #------------------------------------------------------------------------- | 122 #------------------------------------------------------------------------- |
119 # The following tests, corruptD-1.2.*, focus on the offsets contained | 123 # The following tests, corruptD-1.2.*, focus on the offsets contained |
120 # in the first 2 byte of each free-block on the free-list. | 124 # in the first 2 byte of each free-block on the free-list. |
121 # | 125 # |
122 do_test corruptD-1.2.1 { | 126 do_test corruptD-1.2.1 { |
123 restore_file | 127 restore_file |
124 } {} | 128 } {} |
125 do_test corruptD-1.2.2 { | 129 do_test corruptD-1.2.2 { |
126 } {} | 130 } {} |
127 | 131 |
128 #------------------------------------------------------------------------- | 132 #------------------------------------------------------------------------- |
129 # The following tests, corruptD-1.4.*, ... | 133 # The following tests, corruptD-1.4.*, ... |
130 # | 134 # |
131 | 135 |
132 | 136 |
133 #------------------------------------------------------------------------- | 137 #------------------------------------------------------------------------- |
134 # The following tests, corruptD-1.5.*, focus on the offsets contained | 138 # The following tests, corruptD-1.5.*, focus on the offsets contained |
135 # in the cell offset array. | 139 # in the cell offset array. |
136 # | 140 # |
137 # defragmentPage | 141 # defragmentPage |
138 # | 142 # |
139 | 143 |
140 finish_test | 144 finish_test |
OLD | NEW |