From acd337455639a8f515c04859f09f853a84733b60 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 11:38:22 +0000 Subject: [PATCH 1/5] Add the --database option to the fuzzershell test program. FossilOrigin-Name: c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 --- manifest | 13 ++++++------- manifest.uuid | 2 +- tool/fuzzershell.c | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 322b8def98..d68e6d812a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sinitialization\slogic\sin\sCREATE\sTABLE\sAS\sso\sthat\sthe\scorrect\saffinities\nare\sapplied\sto\sall\svalues\sbeing\sinserted\sinto\sthe\snew\stable,\seven\sif\sthe\nRHS\sis\sa\scompound\sSELECT.\s\sFix\sfor\sticket\s[f2ad7de056ab1dc9200]. -D 2015-05-20T17:36:49.966 +C Add\sthe\s--database\soption\sto\sthe\sfuzzershell\stest\sprogram. +D 2015-05-22T11:38:22.072 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1230,7 +1230,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/fuzzershell.c e8be9a8bd8e0e7814592c5e3e38de99ad7beee83 +F tool/fuzzershell.c e35a3e0918349f2a9e0498c17c6fe5a6c7d61d86 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1278,8 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c403502cdce8b82e570e6fc49ab7f5144800c189 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 -R a7c7024ecc6e55965138342c00704c17 -T +closed 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 +P 6a0cf3ce9e68d0127f9653232e588ed59d34eca5 +R 549a709a6f5e577976c5b6d0eb103940 U drh -Z fd6f77c4d4a68df5c93e64187bb026e9 +Z 07941c2a844d4926d98c426b503acb2a diff --git a/manifest.uuid b/manifest.uuid index af099e8f47..ac2e3ceb4c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a0cf3ce9e68d0127f9653232e588ed59d34eca5 \ No newline at end of file +c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c index 4eea55ba0e..6890c0be1e 100644 --- a/tool/fuzzershell.c +++ b/tool/fuzzershell.c @@ -321,6 +321,7 @@ static void showHelp(void){ "and then evaluate each block of SQL contained therein.\n" "Options:\n" " --autovacuum Enable AUTOVACUUM mode\n" +" --database FILE Use database FILE instead of an in-memory database\n" " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" " --help Show this help text\n" " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" @@ -453,6 +454,7 @@ int main(int argc, char **argv){ int jj; /* Loop counter for azInFile[] */ sqlite3_int64 iBegin; /* Start time for the whole program */ sqlite3_int64 iStart, iEnd; /* Start and end-times for a test case */ + const char *zDbName; /* Name of an on-disk database file to open */ iBegin = timeOfDay(); zFailCode = getenv("TEST_FAILURE"); @@ -466,6 +468,11 @@ int main(int argc, char **argv){ if( strcmp(z,"autovacuum")==0 ){ doAutovac = 1; }else + if( strcmp(z,"database")==0 ){ + if( i>=argc-1 ) abendError("missing argument on %s\n", argv[i]); + zDbName = argv[i+1]; + i += 1; + }else if( strcmp(z, "f")==0 && i+1 Date: Fri, 22 May 2015 12:37:37 +0000 Subject: [PATCH 2/5] Fix an assert in btree.c that can be false when using a corrupted database file. FossilOrigin-Name: a6eb2a39357c35dc13d549ef86c785ff5c69938a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d68e6d812a..debf5f12bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--database\soption\sto\sthe\sfuzzershell\stest\sprogram. -D 2015-05-22T11:38:22.072 +C Fix\san\sassert\sin\sbtree.c\sthat\scan\sbe\sfalse\swhen\susing\sa\scorrupted\sdatabase\nfile. +D 2015-05-22T12:37:37.573 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 30a80340481098d699398cba3536c895373b2e2c +F src/btree.c dbc8f9207278c109c3f38c9dc5f550c8bb5080d8 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c d5d9090788118178190c5724c19f93953b8c7a4e @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6a0cf3ce9e68d0127f9653232e588ed59d34eca5 -R 549a709a6f5e577976c5b6d0eb103940 +P c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 +R b9e753c0683555ed773ae3f4504e148b U drh -Z 07941c2a844d4926d98c426b503acb2a +Z f51f66c2118a09b9970e631fa314a714 diff --git a/manifest.uuid b/manifest.uuid index ac2e3ceb4c..a98c44dfeb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 \ No newline at end of file +a6eb2a39357c35dc13d549ef86c785ff5c69938a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4831657fcc..5e561cbcf4 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7860,7 +7860,8 @@ static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){ pgnoRoot==PENDING_BYTE_PAGE(pBt) ){ pgnoRoot++; } - assert( pgnoRoot>=3 ); + assert( pgnoRoot>=3 || CORRUPT_DB ); + testcase( pgnoRoot<3 ); /* Allocate a page. The page that currently resides at pgnoRoot will ** be moved to the allocated page (unless the allocated page happens From afe028a8153e8d10872f9363fc95c5bb8c896d57 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 13:09:50 +0000 Subject: [PATCH 3/5] Fix two faulty assert statements discovered by fuzzing. FossilOrigin-Name: 799817bfb2bc95963c0e0d70063c4cb15c94ef74 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 3 ++- src/insert.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index debf5f12bd..b06174bcb6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert\sin\sbtree.c\sthat\scan\sbe\sfalse\swhen\susing\sa\scorrupted\sdatabase\nfile. -D 2015-05-22T12:37:37.573 +C Fix\stwo\sfaulty\sassert\sstatements\sdiscovered\sby\sfuzzing. +D 2015-05-22T13:09:50.891 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c dbc8f9207278c109c3f38c9dc5f550c8bb5080d8 +F src/btree.c 0eb4eb39e75be6170f1e59f7d6aabedaefb19938 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c d5d9090788118178190c5724c19f93953b8c7a4e @@ -210,7 +210,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 8176ba5bad8fcef643558ca5708f33ed05a4035a +F src/insert.c 35b7816918406ec49fbcc6c7fa7ab622597f662e F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 -R b9e753c0683555ed773ae3f4504e148b +P a6eb2a39357c35dc13d549ef86c785ff5c69938a +R d9917d1c8ed4ffaff7f5ca236b5ad758 U drh -Z f51f66c2118a09b9970e631fa314a714 +Z d8611b43fb13ded0a9ff190ab5f2029c diff --git a/manifest.uuid b/manifest.uuid index a98c44dfeb..d18f783771 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a6eb2a39357c35dc13d549ef86c785ff5c69938a \ No newline at end of file +799817bfb2bc95963c0e0d70063c4cb15c94ef74 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 5e561cbcf4..6b7da394ac 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8011,7 +8011,8 @@ static int clearDatabasePage( rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ - assert( pPage->intKey ); + assert( pPage->intKey || CORRUPT_DB ); + testcase( !pPage->intKey ); *pnChange += pPage->nCell; } if( freePageFlag ){ diff --git a/src/insert.c b/src/insert.c index c794ae4f56..18dbfed8b2 100644 --- a/src/insert.c +++ b/src/insert.c @@ -42,7 +42,7 @@ void sqlite3OpenTable( }else{ Index *pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk!=0 ); - assert( pPk->tnum=pTab->tnum ); + assert( pPk->tnum==pTab->tnum ); sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pPk); VdbeComment((v, "%s", pTab->zName)); From 6b76418e67e8ec93caba0a13139a7fcfd5b8952c Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 22 May 2015 16:08:42 +0000 Subject: [PATCH 4/5] Have r-tree prefer to use the constraint "col MATCH ?" over "rowid = ?". FossilOrigin-Name: b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 --- ext/rtree/rtree.c | 15 ++++++++++++++- ext/rtree/rtreeE.test | 8 ++++++++ manifest | 17 +++++++++-------- manifest.uuid | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index c14c04cd05..553c2fb01b 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1669,17 +1669,30 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ Rtree *pRtree = (Rtree*)tab; int rc = SQLITE_OK; int ii; + int bMatch = 0; /* True if there exists a MATCH constraint */ i64 nRow; /* Estimated rows returned by this scan */ int iIdx = 0; char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; memset(zIdxStr, 0, sizeof(zIdxStr)); + /* Check if there exists a MATCH constraint - even an unusable one. If there + ** is, do not consider the lookup-by-rowid plan as using such a plan would + ** require the VDBE to evaluate the MATCH constraint, which is not currently + ** possible. */ + for(ii=0; iinConstraint; ii++){ + if( pIdxInfo->aConstraint[ii].op==SQLITE_INDEX_CONSTRAINT_MATCH ){ + bMatch = 1; + } + } + assert( pIdxInfo->idxStr==0 ); for(ii=0; iinConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; - if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ + if( bMatch==0 && p->usable + && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ + ){ /* We have an equality constraint on the rowid. Use strategy 1. */ int jj; for(jj=0; jj Date: Fri, 22 May 2015 17:29:27 +0000 Subject: [PATCH 5/5] The SRT_Table type for the SelectDest object is now just an SRT_EphemTab for which the ephemeral table has already been allocated. FossilOrigin-Name: b9727e6bbfc3c62c601227e86e62f2f39792fd1d --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/select.c | 20 ++++---------------- src/update.c | 4 +--- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 155d76770a..405292cc69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sr-tree\sprefer\sto\suse\sthe\sconstraint\s"col\sMATCH\s?"\sover\s"rowid\s=\s?". -D 2015-05-22T16:08:42.447 +C The\sSRT_Table\stype\sfor\sthe\sSelectDest\sobject\sis\snow\sjust\san\sSRT_EphemTab\sfor\nwhich\sthe\sephemeral\stable\shas\salready\sbeen\sallocated. +D 2015-05-22T17:29:27.432 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -250,7 +250,7 @@ F src/printf.c 13ce37e5574f9b0682fa86dbcf9faf76b9d82a15 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 99eabf7eff0bfa65b75939b46caa82e2b2133f28 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 95e728e1bdbca2ee45016308e3eb6d19095155cc +F src/select.c 6adad8d698a382f83009eed7b73080273fa993ca F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee F src/sqlite.h.in 0127e418883c2b41f7fbc056bc1033fa56fbd2a5 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -308,7 +308,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c af8cbbca6db6b664ffecafa236b06629ef6d35c4 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f -F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 +F src/update.c 487747b328b7216bb7f6af0695d6937d5c9e605f F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c a6431c92803b975b7322724a7b433e538d243539 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 @@ -1278,8 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 799817bfb2bc95963c0e0d70063c4cb15c94ef74 -Q +b9e45596d823a6659f4ce2450afcd703feb788d8 -R 28f0e486e27f35ba4c09d0bec0224e3e -U dan -Z e4a60b1b66e40fbda6f3bf3e83ae873e +P b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 +R b9824a32563c5717dba8f6fd0e248f54 +U drh +Z 6ae4be6461472ee1a411850c6b256793 diff --git a/manifest.uuid b/manifest.uuid index c5d3ebcd5a..f4cd12aa80 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 \ No newline at end of file +b9727e6bbfc3c62c601227e86e62f2f39792fd1d \ No newline at end of file diff --git a/src/select.c b/src/select.c index fff0cd9a28..8fc2dbde3d 100644 --- a/src/select.c +++ b/src/select.c @@ -816,6 +816,8 @@ static void selectInnerLoop( int r1 = sqlite3GetTempRange(pParse, nPrefixReg+1); testcase( eDest==SRT_Table ); testcase( eDest==SRT_EphemTab ); + testcase( eDest==SRT_Fifo ); + testcase( eDest==SRT_DistFifo ); sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg); #ifndef SQLITE_OMIT_CTE if( eDest==SRT_DistFifo ){ @@ -1231,10 +1233,7 @@ static void generateSortTail( VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan)); } switch( eDest ){ - case SRT_Table: case SRT_EphemTab: { - testcase( eDest==SRT_Table ); - testcase( eDest==SRT_EphemTab ); sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid); sqlite3VdbeChangeP5(v, OPFLAG_APPEND); @@ -2583,15 +2582,14 @@ static int generateOutputSubroutine( */ codeOffset(v, p->iOffset, iContinue); + assert( pDest->eDest!=SRT_Exists ); + assert( pDest->eDest!=SRT_Table ); switch( pDest->eDest ){ /* Store the result as data using a unique key. */ - case SRT_Table: case SRT_EphemTab: { int r1 = sqlite3GetTempReg(pParse); int r2 = sqlite3GetTempReg(pParse); - testcase( pDest->eDest==SRT_Table ); - testcase( pDest->eDest==SRT_EphemTab ); sqlite3VdbeAddOp3(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst, r1); sqlite3VdbeAddOp2(v, OP_NewRowid, pDest->iSDParm, r2); sqlite3VdbeAddOp3(v, OP_Insert, pDest->iSDParm, r1, r2); @@ -2619,16 +2617,6 @@ static int generateOutputSubroutine( break; } -#if 0 /* Never occurs on an ORDER BY query */ - /* If any row exist in the result set, record that fact and abort. - */ - case SRT_Exists: { - sqlite3VdbeAddOp2(v, OP_Integer, 1, pDest->iSDParm); - /* The LIMIT clause will terminate the loop for us */ - break; - } -#endif - /* If this is a scalar select that is part of an expression, then ** store the results in the appropriate memory cell and break out ** of the scan loop. diff --git a/src/update.c b/src/update.c index 3af4017f1b..f8347448a1 100644 --- a/src/update.c +++ b/src/update.c @@ -743,12 +743,10 @@ static void updateVirtualTable( */ assert( v ); ephemTab = pParse->nTab++; - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0)); - sqlite3VdbeChangeP5(v, BTREE_UNORDERED); /* fill the ephemeral table */ - sqlite3SelectDestInit(&dest, SRT_Table, ephemTab); + sqlite3SelectDestInit(&dest, SRT_EphemTab, ephemTab); sqlite3Select(pParse, pSelect, &dest); /* Generate code to scan the ephemeral table and call VUpdate. */