| OLD | NEW |
| (Empty) |
| 1 # 2007 Sept 7 | |
| 2 # | |
| 3 # The author disclaims copyright to this source code. In place of | |
| 4 # a legal notice, here is a blessing: | |
| 5 # | |
| 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. | |
| 9 # | |
| 10 #*********************************************************************** | |
| 11 # This file implements regression tests for SQLite library. | |
| 12 # | |
| 13 # This file implements tests to make sure SQLite does not crash or | |
| 14 # segfault if it sees a corrupt database file. | |
| 15 # | |
| 16 # $Id: corrupt4.test,v 1.1 2007/09/07 14:32:07 drh Exp $ | |
| 17 | |
| 18 set testdir [file dirname $argv0] | |
| 19 source $testdir/tester.tcl | |
| 20 | |
| 21 # We must have the page_size pragma for these tests to work. | |
| 22 # | |
| 23 ifcapable !pager_pragmas { | |
| 24 finish_test | |
| 25 return | |
| 26 } | |
| 27 | |
| 28 # Create a database with a freelist containing at least two pages. | |
| 29 # | |
| 30 do_test corrupt4-1.1 { | |
| 31 set bigstring [string repeat 0123456789 200] | |
| 32 execsql { | |
| 33 PRAGMA auto_vacuum=OFF; | |
| 34 PRAGMA page_size=1024; | |
| 35 CREATE TABLE t1(x); | |
| 36 INSERT INTO t1 VALUES($bigstring); | |
| 37 CREATE TABLE t2(y); | |
| 38 INSERT INTO t2 VALUES(1); | |
| 39 DROP TABLE t1; | |
| 40 } | |
| 41 file size test.db | |
| 42 } [expr {1024*4}] | |
| 43 | |
| 44 # Verify that there are two pages on the freelist. | |
| 45 # | |
| 46 do_test corrupt4-1.2 { | |
| 47 execsql {PRAGMA freelist_count} | |
| 48 } {2} | |
| 49 | |
| 50 # Get the page number for the trunk of the freelist. | |
| 51 # | |
| 52 set trunkpgno [hexio_get_int [hexio_read test.db 32 4]] | |
| 53 set baseaddr [expr {($trunkpgno-1)*1024}] | |
| 54 | |
| 55 # Verify that the trunk of the freelist has exactly one | |
| 56 # leaf. | |
| 57 # | |
| 58 do_test corrupt4-1.3 { | |
| 59 hexio_get_int [hexio_read test.db [expr {$::baseaddr+4}] 4] | |
| 60 } {1} | |
| 61 | |
| 62 # Insert a negative number as the number of leaves on the trunk. | |
| 63 # Then try to add a new element to the freelist. | |
| 64 # | |
| 65 do_test corrupt4-1.4 { | |
| 66 hexio_write test.db [expr {$::baseaddr+4}] [hexio_render_int32 -100000000] | |
| 67 db close | |
| 68 sqlite3 db test.db | |
| 69 catchsql { | |
| 70 DROP TABLE t2 | |
| 71 } | |
| 72 } {1 {database disk image is malformed}} | |
| 73 | |
| 74 finish_test | |
| OLD | NEW |