-C Fix\sa\sbug\sin\sthe\smutex-testing\slogic\sintroduced\sby\scheck-in\s(5389).\s(CVS\s5390)
-D 2008-07-10T20:41:50
+C Additional\stest\scoverage\sin\sbtree.c.\s\sAdded\scorruption\stests\sfor\nthe\sptrmap\spages\sof\san\sautovacuumed\sdatabase\s(corrupt8.test).\s(CVS\s5391)
+D 2008-07-11T02:21:41
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
-F src/btree.c 61c4752f4e05a5905d95170b0b5ddb24fb143b02
+F src/btree.c 71ba242014031cc6b30761094adad35ad4896a19
F src/btree.h 9373128fbd6509a281e0d356cb15f9cffbfa876c
F src/btreeInt.h d59e58d39950a17c0fb7e004c90ab7696d3e7df5
F src/build.c bac7233d984be3805aaa41cf500f7ee12dc97249
F test/corrupt5.test 7796d5bdfe155ed824cee9dff371f49da237cfe0
F test/corrupt6.test e69b877d478224deab7b66844566258cecacd25e
F test/corrupt7.test f0ff354eb2f0a23035fbd06724b87cac95b55cc1
+F test/corrupt8.test c8ebf7cfe9fca7818a71907a2e433c4a38dbf838
F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89
F test/crash2.test 26d7a4c5520201e5de2c696ea51ab946b59dc0e9
F test/crash3.test 0b09687ae1a3ccbcefdfaeb4b963e26e36255d76
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P ed8b2525006ae7f8cacd01b291760513fdbdff57
-R efb7a3b7b52866a48ca989ffc22b1e05
+P 8fc462b6b7afe390463ea7b010fd3230d9acc358
+R 4385bebdc0676f5f0e502792343cbd11
U drh
-Z 90b53c53d9eef880479c1542b15e3289
+Z f5f817655b5188ade4dd50e6a7a1f252
-8fc462b6b7afe390463ea7b010fd3230d9acc358
\ No newline at end of file
+620b472133438607c412e0c21d2a27605a89a414
\ No newline at end of file
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.475 2008/07/10 00:32:42 drh Exp $
+** $Id: btree.c,v 1.476 2008/07/11 02:21:41 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
BtLock *pIter;
assert( sqlite3BtreeHoldsMutex(p) );
+ assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
+ assert( p->db!=0 );
/* This is a no-op if the shared-cache is not enabled */
if( !p->sharable ){
** write-cursor does not change.
*/
if(
- !p->db ||
0==(p->db->flags&SQLITE_ReadUncommitted) ||
eLock==WRITE_LOCK ||
iTab==MASTER_ROOT
BtLock *pIter;
assert( sqlite3BtreeHoldsMutex(p) );
+ assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
+ assert( p->db!=0 );
/* This is a no-op if the shared-cache is not enabled */
if( !p->sharable ){
** the ReadUncommitted flag.
*/
if(
- (p->db) &&
(p->db->flags&SQLITE_ReadUncommitted) &&
(eLock==READ_LOCK) &&
iTable!=MASTER_ROOT
** for the overflow page.
*/
static int ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell){
- if( pCell ){
- CellInfo info;
- sqlite3BtreeParseCellPtr(pPage, pCell, &info);
- assert( (info.nData+(pPage->intKey?0:info.nKey))==info.nPayload );
- if( (info.nData+(pPage->intKey?0:info.nKey))>info.nLocal ){
- Pgno ovfl = get4byte(&pCell[info.iOverflow]);
- return ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno);
- }
+ CellInfo info;
+ assert( pCell!=0 );
+ sqlite3BtreeParseCellPtr(pPage, pCell, &info);
+ assert( (info.nData+(pPage->intKey?0:info.nKey))==info.nPayload );
+ if( (info.nData+(pPage->intKey?0:info.nKey))>info.nLocal ){
+ Pgno ovfl = get4byte(&pCell[info.iOverflow]);
+ return ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno);
}
return SQLITE_OK;
}
** Allocate nByte bytes of space on a page.
**
** Return the index into pPage->aData[] of the first byte of
-** the new allocation. Or return 0 if there is not enough free
-** space on the page to satisfy the allocation request.
+** the new allocation. The caller guarantees that there is enough
+** space. This routine will never fail.
**
** If the page contains nBytes of free space but does not contain
** nBytes of contiguous free space, then this routine automatically
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
assert( pPage->pBt );
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
- if( nByte<4 ) nByte = 4;
- if( pPage->nFree<nByte || pPage->nOverflow>0 ) return 0;
+ assert( nByte>=0 ); /* Minimum cell size is 4 */
+ assert( pPage->nFree>=nByte );
+ assert( pPage->nOverflow==0 );
pPage->nFree -= nByte;
hdr = pPage->hdrOffset;
--- /dev/null
+# 2008 June 11
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests to make sure SQLite does not crash or
+# segfault if it sees a corrupt database file. It specifically focuses
+# on corrupt pointer map pages.
+#
+# $Id: corrupt8.test,v 1.1 2008/07/11 02:21:41 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# We must have the page_size pragma for these tests to work.
+#
+ifcapable !pager_pragmas||!autovacuum {
+ finish_test
+ return
+}
+
+# Create a database to work with.
+#
+do_test corrupt8-1.1 {
+ execsql {
+ PRAGMA auto_vacuum=1;
+ PRAGMA page_size=1024;
+ CREATE TABLE t1(x);
+ INSERT INTO t1(x) VALUES(1);
+ INSERT INTO t1(x) VALUES(2);
+ INSERT INTO t1(x) SELECT x+2 FROM t1;
+ INSERT INTO t1(x) SELECT x+4 FROM t1;
+ INSERT INTO t1(x) SELECT x+8 FROM t1;
+ INSERT INTO t1(x) SELECT x+16 FROM t1;
+ INSERT INTO t1(x) SELECT x+32 FROM t1;
+ INSERT INTO t1(x) SELECT x+64 FROM t1;
+ INSERT INTO t1(x) SELECT x+128 FROM t1;
+ INSERT INTO t1(x) SELECT x+256 FROM t1;
+ CREATE TABLE t2(a,b);
+ INSERT INTO t2 SELECT x, x*x FROM t1;
+ }
+ expr {[file size test.db]>1024*12}
+} {1}
+integrity_check corrupt8-1.2
+
+# Loop through each ptrmap entry. Corrupt the entry and make sure the
+# corruption is detected by the integrity_check.
+#
+for {set i 1024} {$i<2048} {incr i 5} {
+ set oldval [hexio_read test.db $i 1]
+ if {$oldval==0} break
+ hexio_write test.db $i 00
+ do_test corrupt8-2.$i.0 {
+ db close
+ sqlite3 db test.db
+ set x [db eval {PRAGMA integrity_check}]
+ expr {$x!="ok"}
+ } {1}
+ for {set k 1} {$k<=5} {incr k} {
+ if {$k==$oldval} continue
+ hexio_write test.db $i 0$k
+ do_test corrupt8-2.$i.$k {
+ db close
+ sqlite3 db test.db
+ set x [db eval {PRAGMA integrity_check}]
+ expr {$x!="ok"}
+ } {1}
+ }
+ hexio_write test.db $i 06
+ do_test corrupt8-2.$i.6 {
+ db close
+ sqlite3 db test.db
+ set x [db eval {PRAGMA integrity_check}]
+ expr {$x!="ok"}
+ } {1}
+ hexio_write test.db $i $oldval
+ if {$oldval>2} {
+ set i2 [expr {$i+1+$i%4}]
+ set oldval [hexio_read test.db $i2 1]
+ hexio_write test.db $i2 [format %02x [expr {($oldval+1)&0xff}]]
+ do_test corrupt8-2.$i.7 {
+ db close
+ sqlite3 db test.db
+ set x [db eval {PRAGMA integrity_check}]
+ expr {$x!="ok"}
+ } {1}
+ hexio_write test.db $i2 $oldval
+ }
+}
+
+
+finish_test