From 1bc71590c48f38b994e54975eeb8505e201aa3d2 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 8 Jul 2008 17:13:59 +0000 Subject: [PATCH] Test another corruption case in btree.c. And an IO error related scenario. (CVS 5371) FossilOrigin-Name: d74fbb81ca3f973ac46534344e5076afc5dd5491 --- manifest | 18 ++++++++-------- manifest.uuid | 2 +- src/btree.c | 4 ++-- test/corrupt2.test | 51 ++++++++++++++++++++++++++++++++++++++++----- test/ioerr.test | 25 +++++++++++++++++++++- test/softheap1.test | 3 ++- 6 files changed, 84 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 25040de411..a9160c390d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C 3\smore\scoverage\stests\sfor\sbtree.c.\s(CVS\s5370) -D 2008-07-08T15:59:52 +C Test\sanother\scorruption\scase\sin\sbtree.c.\sAnd\san\sIO\serror\srelated\sscenario.\s(CVS\s5371) +D 2008-07-08T17:13:59 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -95,7 +95,7 @@ F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2 -F src/btree.c e00268557794be741e26cbca1cd77aa37e53b1cc +F src/btree.c 965da6ca8bbd51677db5587471a5b0ef08f49786 F src/btree.h b1bd7e0b8c2e33658aaf447cb0d1d94f74664b6b F src/btreeInt.h 02325f04758dba0fcd0c08ac55cd9b189dad61a5 F src/build.c 142ceacdc14e479f337aeb01db631f22683496f8 @@ -242,7 +242,7 @@ F test/collateA.test b8218ab90d1fa5c59dcf156efabb1b2599c580d6 F test/colmeta.test 087c42997754b8c648819832241daf724f813322 F test/conflict.test bb29b052c60a1f7eb6382be77902061d1f305318 F test/corrupt.test af069d971853dbe12af936910bfa49d92f7b16e9 -F test/corrupt2.test 26810e0019a16004b1a7619930801ef1c31531e4 +F test/corrupt2.test e56f45006e7eb3ee680ad3b61c92cc14ae09986e F test/corrupt3.test 263e8bb04e2728df832fddf6973cf54c91db0c32 F test/corrupt4.test acdb01afaedf529004b70e55de1a6f5a05ae7fff F test/corrupt5.test 7796d5bdfe155ed824cee9dff371f49da237cfe0 @@ -356,7 +356,7 @@ F test/insert5.test 509017213328147d3acdfa2c441bfd82362dda41 F test/interrupt.test 42e7cf98646fd9cb4a3b131a93ed3c50b9e149f1 F test/intpkey.test 537669fd535f62632ca64828e435b9e54e8d677f F test/io.test 833a1746518ec3005aa7792f9bcb8f01923ff544 -F test/ioerr.test 7ff1f418eae013dd848583c7f8a8cae938532f55 +F test/ioerr.test f87e5be364a5938996e8741091088845eb9ce802 F test/ioerr2.test 5598405c48842c6c0187daad9eb49eff2c54f80d F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test fc6eddfec2efc2f1ed217b9eae4c1c1d3516ce86 @@ -460,7 +460,7 @@ F test/shared_err.test 776ab7196ecda8b07a075e115b0725806991e151 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/sidedelete.test 736ac1da08b3b1aa62df97fef2fcdb1b660111b9 F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b -F test/softheap1.test c9146eda576eedb62192b771293a2115d9af8456 +F test/softheap1.test 73ebd6e020d2954d965da2072baba5922fc8fb6a F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb @@ -600,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P c5e45dd664198e5b4fc44b316bd4adbc9a6c296b -R 17c4ddff498e4bc2ee18143f2ad0e55f +P 96df0a5fa4bb2b3dfedf034d81704e152cdc63a9 +R bc52d4843754cbd36c0ef3202e607fb2 U danielk1977 -Z a2bfd51b9ad8acbdccd1bedc318ea395 +Z 01c21e73d1086c9de6763f3a0f6454a5 diff --git a/manifest.uuid b/manifest.uuid index a9d623ac0a..e2116df580 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -96df0a5fa4bb2b3dfedf034d81704e152cdc63a9 \ No newline at end of file +d74fbb81ca3f973ac46534344e5076afc5dd5491 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index da4666c081..fa18163723 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.471 2008/07/04 17:52:43 drh Exp $ +** $Id: btree.c,v 1.472 2008/07/08 17:13:59 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -2014,7 +2014,7 @@ static int setChildPtrmaps(MemPage *pPage){ if( !pPage->leaf ){ Pgno childPgno = get4byte(pCell); rc = ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno); - if( rc!=SQLITE_OK ) goto set_child_ptrmaps_out; + if( rc!=SQLITE_OK ) goto set_child_ptrmaps_out; } } diff --git a/test/corrupt2.test b/test/corrupt2.test index 08fb635153..d20e4a9dce 100644 --- a/test/corrupt2.test +++ b/test/corrupt2.test @@ -13,7 +13,7 @@ # This file implements tests to make sure SQLite does not crash or # segfault if it sees a corrupt database file. # -# $Id: corrupt2.test,v 1.12 2008/07/08 15:59:52 danielk1977 Exp $ +# $Id: corrupt2.test,v 1.13 2008/07/08 17:13:59 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -337,7 +337,7 @@ ifcapable autovacuum { } -corruption_test -sqlprep { +set sqlprep { PRAGMA page_size = 1024; CREATE TABLE t1(a INTEGER PRIMARY KEY, b); CREATE INDEX i1 ON t1(b); @@ -348,7 +348,9 @@ corruption_test -sqlprep { INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; -} -corrupt { +} + +corruption_test -sqlprep $sqlprep -corrupt { # Set the page-flags of one of the leaf pages of the index B-Tree to # 0x0D (interpreted by SQLite as "leaf page of a table B-Tree"). # @@ -362,7 +364,46 @@ corruption_test -sqlprep { close $fd } -test { do_test corrupt2-7.1 { - catchsql { SELECT b FROM t1 ORDER BY b } + catchsql { SELECT b FROM t1 ORDER BY b ASC } + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Mess up the page-header of one of the leaf pages of the index B-Tree. + # The corruption is detected as part of an OP_Prev opcode. + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024*2 + 12] + set zCellOffset [read $fd 2] + binary scan $zCellOffset S iCellOffset + seek $fd [expr 1024*2 + $iCellOffset] + set zChild [read $fd 4] + binary scan $zChild I iChild + seek $fd [expr 1024*($iChild-1)+3] + puts -nonewline $fd "\xFFFF" + close $fd +} -test { + do_test corrupt2-7.1 { + catchsql { SELECT b FROM t1 ORDER BY b DESC } + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Set the page-flags of one of the leaf pages of the table B-Tree to + # 0x0A (interpreted by SQLite as "leaf page of an index B-Tree"). + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary -encoding binary + seek $fd [expr 1024*1 + 8] + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)] + puts -nonewline $fd "\x0A" + close $fd +} -test { + do_test corrupt2-8.1 { + catchsql { SELECT * FROM t1 WHERE rowid=1000 } } {1 {database disk image is malformed}} } @@ -389,7 +430,7 @@ corruption_test -sqlprep { puts -nonewline $fd "\x00\x00" close $fd } -test { - do_test corrupt2-8.1 { + do_test corrupt2-9.1 { catchsql { SELECT sql FROM sqlite_master } } {1 {database disk image is malformed}} } diff --git a/test/ioerr.test b/test/ioerr.test index 77d895664e..ef24357490 100644 --- a/test/ioerr.test +++ b/test/ioerr.test @@ -15,7 +15,7 @@ # The tests in this file use special facilities that are only # available in the SQLite test fixture. # -# $Id: ioerr.test,v 1.38 2008/07/08 10:19:58 danielk1977 Exp $ +# $Id: ioerr.test,v 1.39 2008/07/08 17:13:59 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -306,5 +306,28 @@ ifcapable pager_pragmas&&autovacuum { } } +# Usually, after a new page is allocated from the end of the file, it does +# not need to be written to the journal. The exception is when the new page +# shares its sector with an existing page that does need to be journalled. +# This test case provokes this condition to test for the sake of coverage +# that an IO error while journalling the coresident page is handled correctly. +# +sqlite3_simulate_device -char {} -sectorsize 2048 +do_ioerr_test ioerr-12 -ckrefcount true -erc 1 -tclprep { + db close + sqlite3 db test.db -vfs devsym + + # Create a test database. Page 2 is the root page of table t1. The only + # row inserted into t1 has an overflow page - page 3. Page 3 will be + # coresident on the 2048 byte sector with the next page to be allocated. + # + db eval { PRAGMA page_size = 1024 } + db eval { CREATE TABLE t1(x) } + db eval { INSERT INTO t1 VALUES(randomblob(1100)); } +} -tclbody { + db eval { INSERT INTO t1 VALUES(randomblob(2000)); } +} +sqlite3_simulate_device -char {} -sectorsize 0 + finish_test diff --git a/test/softheap1.test b/test/softheap1.test index f71fa9a8a7..5a060958f5 100644 --- a/test/softheap1.test +++ b/test/softheap1.test @@ -13,7 +13,7 @@ # A database corruption bug that occurs in auto_vacuum mode when # the soft_heap_limit is set low enough to be triggered. # -# $Id: softheap1.test,v 1.4 2008/01/19 20:11:26 drh Exp $ +# $Id: softheap1.test,v 1.5 2008/07/08 17:13:59 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -44,6 +44,7 @@ do_test softheap1-1.1 { PRAGMA integrity_check; } } {ok} + sqlite3_soft_heap_limit $soft_limit finish_test