diff --git a/manifest b/manifest index ee7e6c8dc2..f1f7cfa2b7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sall\srecent\strunk\schanges. -D 2013-11-27T21:53:51.759 +C Merge\sall\srecent\s3.8.2\sbeta\schanges\sfrom\strunk. +D 2013-12-02T21:58:19.732 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 06b851f767034811d4f6e159367c453dc28d3925 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -180,7 +180,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 1809a7caa2504233bdddd12f5018422421789537 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c ec8a4dcac5c1ec1ba9705b8c5a13e62167958317 +F src/btree.c fe6c95c57fd14ed4b3329f4b5bb08132fe7c322d F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0 F src/build.c 07054d45319953e54a89d726e589a423e9c1c590 @@ -193,7 +193,7 @@ F src/expr.c 31a2b65339f6c3795d4cfa5e99798cd72f9fdfdf F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 2ab0f5384b70594468ef3ac5c7ed8ca24bfd17d5 F src/func.c ef30d26ae4d79bbc7300c74e77fd117a0ba30235 -F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759 +F src/global.c 1d7bb7ea8254ae6a68ed9bfaf65fcb3d1690b486 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 @@ -202,7 +202,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c ce3f0087c9976bed2c8955ad55f99353f0cdc8fb +F src/main.c f432ac8a820b4b9fbfd41c40c686f8d971791abe F src/malloc.c 543a8eb5508eaf4cadf55a9b503379eba2088128 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b @@ -235,15 +235,15 @@ F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c d41381d80a22d3a83352aeca274cccf264ac277a F src/shell.c 936a72ff784efff3832cce274a96ed0b036e6758 -F src/sqlite.h.in e7a96fad3f5a2e96f5b69cf395d3dfa657f4ab59 +F src/sqlite.h.in afb55228e32532456938c5c4ac0b9aa0828f3677 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h dad3dff932c055304fc75b339f2cf68aab9cf19e +F src/sqliteInt.h f4056513ed1a1690f1ff0ec6df15b38581676f2f F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/tclsqlite.c 758fa6b6cfd39330db8b71b1f94e46f03ef375b8 -F src/test1.c 5757066e503a8ed51313cb3a5d9bcdcced2991a9 +F src/test1.c 760e0419705f712d80595f47199568cd7e3b57a4 F src/test2.c 7355101c085304b90024f2261e056cdff13c6c35 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df @@ -292,13 +292,13 @@ F src/tokenize.c ec4c1a62b890bf1dbcdb966399e140b904c700a4 F src/trigger.c d84e1f3669e9a217731a14a9d472b1c7b87c87ba F src/update.c 046d7df2a4b3d85442a758f484eb2d40a48b5465 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 -F src/util.c cbe054290f780fcd472b89d701c7404c51ec9684 +F src/util.c c1d47254d805074226eb68bab2327f2559799d88 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 F src/vdbe.c 9c6fb9ed1b9165427b0fdc812bc9c48c031f77da F src/vdbe.h b7bfa7b468fcad2cf1890969fe7459325da00385 F src/vdbeInt.h 1a5c604f33a5d46c839fee0cab16743aa3e1bc2e F src/vdbeapi.c e80d6d9dea792bd823cb64ae05cba446a7b3556a -F src/vdbeaux.c 9270db4725c0143e572a2df660fabac7104a9db3 +F src/vdbeaux.c aad7d1714be08e05999a92f366328173286ecaac F src/vdbeblob.c a2809461743e0b9dd9be871149ac65e8d2c80c08 F src/vdbemem.c af650c2019dc197f062440cdb4650b7204e648bf F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 @@ -404,22 +404,22 @@ F test/conflict.test 841bcf7cabbfca39c577eb8411ea8601843b46a8 F test/conflict2.test 3ed0b6ec3c2cb8acebbc89677ea0e58c01aaa1ff F test/conflict3.test dec0634c0f31dec9a4b01c63063e939f0cd21b6b F test/contrib01.test 2a1cbc0f2f48955d7d073f725765da6fbceda6b4 -F test/corrupt.test 4aabd06cff3fe759e3e658bcc17b71789710665e -F test/corrupt2.test 9c0ab4becd50e9050bc1ebb8675456a4e5587bf0 -F test/corrupt3.test 889d7cdb811800303aa722d7813fe8a4299cf726 -F test/corrupt4.test b963f9e01e0f92d15c76fb0747876fd4b96dc30a -F test/corrupt5.test c23da7bfb20917cc7fdbb13ee25c7cc4e9fffeff -F test/corrupt6.test 4e4161aef1f30b9f34582bb4142334b7f47eacae -F test/corrupt7.test a90caf89c7d7cb7893ea4d92529bd0c129317ee4 -F test/corrupt8.test 48eb37ffb9a03bceada62219e2bd4c92f4b0cb75 -F test/corrupt9.test 959179e68dc0b7b99f424cf3e0381c86dcdd0112 -F test/corruptA.test fafa652aa585753be4f6b62ff0bb250266eaf7ce -F test/corruptB.test 20d4a20cbed23958888c3e8995b424a47223d647 -F test/corruptC.test 62a767fe64acb1975f58cc6171192839c783edbb -F test/corruptD.test 3b09903a2e2fe07ecafe775fea94177f8a4bb34f -F test/corruptE.test d3a3d7e864a95978195741744dda4abfd8286018 -F test/corruptF.test 1c7b6f77cf3f237fb7fbb5b61d6c921fd4c7b993 -F test/corruptG.test c67fd860e9e3943bc90b856a3049c9a28827167e +F test/corrupt.test 141c39ea650c1365e85a49e402fa05cb9617fb97 +F test/corrupt2.test f2064e0bf934124cc38868fd8badb8f0dd67b552 +F test/corrupt3.test 4b548d0bbe2933bc81d3f54099a05fc4d28aff18 +F test/corrupt4.test b99652079d542b21f4965f6248703b983e40fe80 +F test/corrupt5.test 8ead52af76006f3286e9396cb41898018ccea107 +F test/corrupt6.test 269548d19427ac554c830763b1c5ea54a0252f80 +F test/corrupt7.test 22cc644c2e76c9804bc844121267aa6f8f7c0ded +F test/corrupt8.test 2399dfe40d2c0c63af86706e30f3e6302a8d0516 +F test/corrupt9.test 730a3db08d4ab9aa43392ea30d9c2b4879cbff85 +F test/corruptA.test 53e56dafd180addcdadb402244b8cb9771d2ba26 +F test/corruptB.test 73a8d6c0b9833697ecf16b63e3c5c05c945b5dec +F test/corruptC.test 02405cf7ed0c1e989060e1aab6d02ffbc3906fbb +F test/corruptD.test b3c205fac7952b1de645ce44bb02335cd9e3e040 +F test/corruptE.test 193b4ca4e927e77c1d5f4f56203ddc998432a7ee +F test/corruptF.test be9fde98e4c93648f1ba52b74e5318edc8f59fe4 +F test/corruptG.test c150f156dace653c00a121ad0f5772a0568c41ba F test/count.test 42a251178e32f617eda33f76236a7f79825a50b5 F test/coveridxscan.test cdb47d01acc4a634a34fd25abe85189e0d0f1e62 F test/crash.test fb9dc4a02dcba30d4aa5c2c226f98b220b2b959f @@ -484,7 +484,7 @@ F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d F test/fkey5.test 8a1fde4e7721ae00b05b3178888833726ca2df8d F test/fkey6.test 6697550baa38505c9952eff130ab26a2d156c0cc F test/fkey7.test e31d0e71a41c1d29349a16448d6c420e2c53a8fc -F test/fkey_malloc.test bb74c9cb8f8fceed03b58f8a7ef2df98520bbd51 +F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7 @@ -638,7 +638,7 @@ F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4 F test/interrupt.test dfe9a67a94b0b2d8f70545ba1a6cca10780d71cc F test/intpkey.test 7506090fc08e028712a8bf47e5f54111947e3844 F test/io.test 3a7abcef18727cc0f2399e04b0e8903eccae50f8 -F test/ioerr.test 40bb2cfcab63fb6aa7424cd97812a84bc16b5fb8 +F test/ioerr.test 2a24bd6ed5a8b062e64bfe1f6cf94fb25e92210d F test/ioerr2.test 9d71166f8466eda510f1af6137bdabaa82b5408d F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c @@ -835,7 +835,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c 184ded13ffe61df44d6e2ac9985b61a6417d5311 +F test/speedtest1.c 4f1e34b6af9af0b59ca11b57d62c3cd851990fba F test/spellfix.test 8c40b169b104086d8795781f670ba3c786d6d8be F test/sqllimits1.test b1aae27cc98eceb845e7f7adf918561256e31298 F test/stat.test c8eccfe8fcd3f3cfc864ce22d5b9e803a3c69940 @@ -854,8 +854,8 @@ F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 F test/tclsqlite.test a7308276aad2e6c0bfb5b0414424dd0d9cc0cad7 F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 -F test/temptrigger.test 0a48d94222d50e6e50d72ac103606c4f8e7cbb81 -F test/tester.tcl a0f63e910f954acd367a5951e3a4f3ef9c32067a +F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1 +F test/tester.tcl f1316f88470a06db624fae39d5279ce21ed49652 F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5 F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58 F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7 @@ -1004,7 +1004,7 @@ F test/tpch01.test 8f4ac52f62f3e9f6bce0889105aecdf0275e331b F test/trace.test 4b36a41a3e9c7842151af6da5998f5080cdad9e5 F test/trace2.test e7a988fdd982cdec62f1f1f34b0360e6476d01a0 F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6 -F test/trans2.test d5337e61de45e66b1fcbf9db833fa8c82e624b22 +F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 F test/trans3.test 373ac5183cc56be69f48ae44090e7f672939f732 F test/transitive1.test 03f532954f46cdf5608f7766bff0b0c52bf2a7cd F test/trigger1.test dc47573ac79ffe0ee3eecaa517d70d8dacbccd03 @@ -1160,7 +1160,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P fc9ae839569eb28eb734c52d95676c59b2e27494 81891288d9f281cf2ceb4cd701c0c3231b1bab19 -R 82cfa20fdf0a662273b8437808c19755 +P 3a2a1bd47875e114d8e6f31c1768908f401d2861 bc8eacc7f71413184ef5be1412e51f8fd7174cd1 +R 23fdb9bec4ca7fb51a8c2b5b5649fa63 U drh -Z 5ce6e39b92ce4cf1a9fbbd5b784d1d3b +Z d6ca9769225d05465b3da41409f1cf6b diff --git a/manifest.uuid b/manifest.uuid index b00a655abf..b7ae0d856a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3a2a1bd47875e114d8e6f31c1768908f401d2861 \ No newline at end of file +67c34ccfa9596a923695dc4994ec87b331f8326c \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 27e7146893..30fdf4256f 100644 --- a/src/btree.c +++ b/src/btree.c @@ -694,6 +694,10 @@ static int btreeMoveto( ); if( pIdxKey==0 ) return SQLITE_NOMEM; sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey); + if( pIdxKey->nField==0 ){ + sqlite3DbFree(pCur->pKeyInfo->db, pFree); + return SQLITE_CORRUPT_BKPT; + } }else{ pIdxKey = 0; } diff --git a/src/global.c b/src/global.c index 7b02cf2130..1ee3f6436f 100644 --- a/src/global.c +++ b/src/global.c @@ -148,6 +148,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { SQLITE_USE_URI, /* bOpenUri */ SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ 0x7ffffffe, /* mxStrlen */ + 0, /* neverCorrupt */ 128, /* szLookaside */ 500, /* nLookaside */ {0,0,0,0,0,0,0,0}, /* m */ @@ -183,7 +184,6 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { #endif }; - /* ** Hash table for global functions - functions common to all ** database connections. After initialization, this table is diff --git a/src/main.c b/src/main.c index 6bd5ab0246..7c8f1739f9 100644 --- a/src/main.c +++ b/src/main.c @@ -3317,6 +3317,19 @@ int sqlite3_test_control(int op, ...){ } #endif + /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int); + ** + ** Set or clear a flag that indicates that the database file is always well- + ** formed and never corrupt. This flag is clear by default, indicating that + ** database files might have arbitrary corruption. Setting the flag during + ** testing causes certain assert() statements in the code to be activated + ** that demonstrat invariants on well-formed database files. + */ + case SQLITE_TESTCTRL_NEVER_CORRUPT: { + sqlite3Config.neverCorrupt = va_arg(ap, int); + break; + } + } va_end(ap); #endif /* SQLITE_OMIT_BUILTIN_TEST */ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 926ac12b7d..f67c42a8c8 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -6069,7 +6069,8 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 -#define SQLITE_TESTCTRL_LAST 19 +#define SQLITE_TESTCTRL_NEVER_CORRUPT 20 +#define SQLITE_TESTCTRL_LAST 20 /* ** CAPI3REF: SQLite Runtime Status diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 943b93cc30..0c4159e622 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2550,6 +2550,7 @@ struct Sqlite3Config { int bOpenUri; /* True to interpret filenames as URIs */ int bUseCis; /* Use covering indices for full-scans */ int mxStrlen; /* Maximum string length */ + int neverCorrupt; /* Database is always well-formed */ int szLookaside; /* Default lookaside buffer size */ int nLookaside; /* Default lookaside buffer count */ sqlite3_mem_methods m; /* Low-level memory allocation interface */ @@ -2586,6 +2587,24 @@ struct Sqlite3Config { #endif }; +/* +** This macro is used inside of assert() statements to indicate that +** the assert is only valid on a well-formed database. Instead of: +** +** assert( X ); +** +** One writes: +** +** assert( X || CORRUPT_DB ); +** +** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate +** that the database is definitely corrupt, only that it might be corrupt. +** For most test cases, CORRUPT_DB is set to false using a special +** sqlite3_test_control(). This enables assert() statements to prove +** things that are always true for well-formed databases. +*/ +#define CORRUPT_DB (sqlite3Config.neverCorrupt==0) + /* ** Context pointer passed down through the tree-walk. */ diff --git a/src/test1.c b/src/test1.c index d8a9e52d21..e0c16e13ae 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5453,6 +5453,37 @@ static int reset_prng_state( return TCL_OK; } +/* +** tclcmd: database_may_be_corrupt +** +** Indicate that database files might be corrupt. In other words, set the normal +** state of operation. +*/ +static int database_may_be_corrupt( + ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int objc, /* Number of arguments */ + Tcl_Obj *CONST objv[] /* Command arguments */ +){ + sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 0); + return TCL_OK; +} +/* +** tclcmd: database_never_corrupt +** +** Indicate that database files are always well-formed. This enables extra assert() +** statements that test conditions that are always true for well-formed databases. +*/ +static int database_never_corrupt( + ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ + Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ + int objc, /* Number of arguments */ + Tcl_Obj *CONST objv[] /* Command arguments */ +){ + sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 1); + return TCL_OK; +} + /* ** tclcmd: pcache_stats */ @@ -6331,6 +6362,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "save_prng_state", save_prng_state, 0 }, { "restore_prng_state", restore_prng_state, 0 }, { "reset_prng_state", reset_prng_state, 0 }, + { "database_never_corrupt", database_never_corrupt, 0}, + { "database_may_be_corrupt", database_may_be_corrupt, 0}, { "optimization_control", optimization_control,0}, #if SQLITE_OS_WIN { "lock_win32_file", win32_file_lock, 0 }, diff --git a/src/util.c b/src/util.c index 5aa8af68d9..e59f5238f8 100644 --- a/src/util.c +++ b/src/util.c @@ -465,12 +465,12 @@ static int compare2pow63(const char *zNum, int incr){ ** If the zNum value is representable as a 64-bit twos-complement ** integer, then write that value into *pNum and return 0. ** -** If zNum is exactly 9223372036854665808, return 2. This special -** case is broken out because while 9223372036854665808 cannot be a -** signed 64-bit integer, its negative -9223372036854665808 can be. +** If zNum is exactly 9223372036854775808, return 2. This special +** case is broken out because while 9223372036854775808 cannot be a +** signed 64-bit integer, its negative -9223372036854775808 can be. ** ** If zNum is too big for a 64-bit integer and is not -** 9223372036854665808 or if zNum contains any non-numeric text, +** 9223372036854775808 or if zNum contains any non-numeric text, ** then return 1. ** ** length is the number of bytes in the string (bytes, not characters). diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 65aacf7e34..29a2251e08 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -3114,9 +3114,9 @@ int sqlite3VdbeRecordCompare( idx1 = getVarint32(aKey1, szHdr1); d1 = szHdr1; - assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField ); + assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB ); assert( pKeyInfo->aSortOrder!=0 ); - assert( idx1nField ); + assert( (idx1<=szHdr1 && inField) || CORRUPT_DB ); do{ u32 serial_type1; diff --git a/test/corrupt.test b/test/corrupt.test index 09f3c5bd7c..3e49a9ff18 100644 --- a/test/corrupt.test +++ b/test/corrupt.test @@ -25,6 +25,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # Construct a large database for testing. # do_test corrupt-1.1 { diff --git a/test/corrupt2.test b/test/corrupt2.test index 744a76ed04..805a6148f0 100644 --- a/test/corrupt2.test +++ b/test/corrupt2.test @@ -23,6 +23,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + set presql "" catch { set presql "$::G(perm:presql);" } unset -nocomplain ::G(perm:presql) diff --git a/test/corrupt3.test b/test/corrupt3.test index a3827227b7..436a466189 100644 --- a/test/corrupt3.test +++ b/test/corrupt3.test @@ -23,6 +23,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas||direct_read { diff --git a/test/corrupt4.test b/test/corrupt4.test index 19061134f6..24db60fd52 100644 --- a/test/corrupt4.test +++ b/test/corrupt4.test @@ -23,6 +23,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas { diff --git a/test/corrupt5.test b/test/corrupt5.test index dca06e5fec..3f5099630e 100644 --- a/test/corrupt5.test +++ b/test/corrupt5.test @@ -19,6 +19,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas { diff --git a/test/corrupt6.test b/test/corrupt6.test index c0dcedf3d9..7d90c4a3ba 100644 --- a/test/corrupt6.test +++ b/test/corrupt6.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas { diff --git a/test/corrupt7.test b/test/corrupt7.test index ad566560f7..db92cf1de9 100644 --- a/test/corrupt7.test +++ b/test/corrupt7.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas { diff --git a/test/corrupt8.test b/test/corrupt8.test index 012beb562e..d7bceba31c 100644 --- a/test/corrupt8.test +++ b/test/corrupt8.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas||!autovacuum { diff --git a/test/corrupt9.test b/test/corrupt9.test index f199452f95..bb37758b17 100644 --- a/test/corrupt9.test +++ b/test/corrupt9.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # We must have the page_size pragma for these tests to work. # ifcapable !pager_pragmas { diff --git a/test/corruptA.test b/test/corruptA.test index 8b76d3a201..bb9912bd2b 100644 --- a/test/corruptA.test +++ b/test/corruptA.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # Create a database to work with. # diff --git a/test/corruptB.test b/test/corruptB.test index 0ff2d6e9e0..c51cb57680 100644 --- a/test/corruptB.test +++ b/test/corruptB.test @@ -30,6 +30,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + do_test corruptB-1.1 { execsql { diff --git a/test/corruptC.test b/test/corruptC.test index 34e81a1be8..adf6f44c44 100644 --- a/test/corruptC.test +++ b/test/corruptC.test @@ -27,6 +27,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # Construct a compact, dense database for testing. # do_test corruptC-1.1 { @@ -202,6 +206,10 @@ do_test corruptC-2.8 { } {1 {database disk image is malformed}} # corruption (seed 170434) +# +# UPDATE: Prior to 3.8.2, this used to return SQLITE_CORRUPT. It no longer +# does. That is Ok, the point of these tests is to verify that no buffer +# overruns or overreads can be caused by corrupt databases. do_test corruptC-2.9 { db close forcecopy test.bu test.db @@ -211,7 +219,7 @@ do_test corruptC-2.9 { sqlite3 db test.db catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} -} {1 {database disk image is malformed}} +} {0 {}} # corruption (seed 186504) do_test corruptC-2.10 { diff --git a/test/corruptD.test b/test/corruptD.test index 2423cd428e..63474584c3 100644 --- a/test/corruptD.test +++ b/test/corruptD.test @@ -19,6 +19,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + #-------------------------------------------------------------------------- # OVERVIEW # diff --git a/test/corruptE.test b/test/corruptE.test index 48292ab2e9..4d5b5db3d6 100644 --- a/test/corruptE.test +++ b/test/corruptE.test @@ -24,6 +24,10 @@ source $testdir/tester.tcl # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on. # ifcapable oversize_cell_check { diff --git a/test/corruptF.test b/test/corruptF.test index 64c6eb890b..8c4fd84219 100644 --- a/test/corruptF.test +++ b/test/corruptF.test @@ -19,6 +19,10 @@ set testprefix corruptF # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + proc str {i} { format %08d $i } # Create a 6 page database containing a single table - t1. Table t1 diff --git a/test/corruptG.test b/test/corruptG.test index c34911195c..11253fd12c 100644 --- a/test/corruptG.test +++ b/test/corruptG.test @@ -19,6 +19,10 @@ set testprefix corruptG # do_not_use_codec +# These tests deal with corrupt database files +# +database_may_be_corrupt + # Create a simple database with a single entry. Then corrupt the # header-size varint on the index payload so that it maps into a # negative number. Try to use the database. diff --git a/test/fkey_malloc.test b/test/fkey_malloc.test index b4b5b4eed7..382e6f67d9 100644 --- a/test/fkey_malloc.test +++ b/test/fkey_malloc.test @@ -69,7 +69,10 @@ proc catch_fk_error {zSql} { if {[string match {*foreign key*} $msg]} { return "" } - if {$msg eq "out of memory" || $msg eq "constraint failed"} { + if {$msg eq "out of memory" + || $msg eq "FOREIGN KEY constraint failed" + || $msg eq "constraint failed" + } { error 1 } error $msg diff --git a/test/ioerr.test b/test/ioerr.test index b237439ea2..e59647fe50 100644 --- a/test/ioerr.test +++ b/test/ioerr.test @@ -258,7 +258,7 @@ do_ioerr_test ioerr-10 -ckrefcount true -tclprep { INSERT INTO t1 SELECT (a+500)%900, 'good string' FROM t1; }} msg - if {$msg != "column a is not unique"} { + if {$msg != "UNIQUE constraint failed: t1.a"} { error $msg } } diff --git a/test/speedtest1.c b/test/speedtest1.c index ea9ec2e351..f3e79ec816 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -79,6 +79,12 @@ static int hexDigitValue(char c){ return -1; } +/* Provide an alternative to sqlite3_stricmp() in older versions of +** SQLite */ +#if SQLITE_VERSION_NUMBER<3007011 +# define sqlite3_stricmp strcmp +#endif + /* ** Interpret zArg as an integer value, possibly with suffixes. */ @@ -131,9 +137,12 @@ sqlite3_int64 speedtest1_timestamp(void){ static sqlite3_vfs *clockVfs = 0; sqlite3_int64 t; if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); - if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){ +#if SQLITE_VERSION_NUMBER>=3007000 + if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ clockVfs->xCurrentTimeInt64(clockVfs, &t); - }else{ + }else +#endif + { double r; clockVfs->xCurrentTime(clockVfs, &r); t = (sqlite3_int64)(r*86400000.0); @@ -898,6 +907,7 @@ int main(int argc, char **argv){ /* Database connection statistics printed after both prepared statements ** have been finalized */ +#if SQLITE_VERSION_NUMBER>=3007009 if( showStats ){ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHi, 0); printf("-- Lookaside Slots Used: %d (max %d)\n", iCur,iHi); @@ -912,14 +922,17 @@ int main(int argc, char **argv){ sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHi, 1); printf("-- Page cache hits: %d\n", iCur); sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHi, 1); - printf("-- Page cache misses: %d\n", iCur); + printf("-- Page cache misses: %d\n", iCur); +#if SQLITE_VERSION_NUMBER>=3007012 sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHi, 1); printf("-- Page cache writes: %d\n", iCur); +#endif sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHi, 0); printf("-- Schema Heap Usage: %d bytes\n", iCur); sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHi, 0); printf("-- Statement Heap Usage: %d bytes\n", iCur); } +#endif sqlite3_close(g.db); @@ -928,8 +941,10 @@ int main(int argc, char **argv){ if( showStats ){ sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHi, 0); printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHi); +#if SQLITE_VERSION_NUMBER>=3007000 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHi, 0); printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHi); +#endif sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHi, 0); printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHi); sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHi, 0); diff --git a/test/temptrigger.test b/test/temptrigger.test index d646b672b9..551c620479 100644 --- a/test/temptrigger.test +++ b/test/temptrigger.test @@ -265,10 +265,10 @@ do_test 6.1 { } {} do_execsql_test 6.2 { - SELECT * FROM aux.sqlite_master; + SELECT type,name,tbl_name,sql FROM aux.sqlite_master; INSERT INTO aux.t1 VALUES(1,2,3); } { - table t1 t1 2 {CREATE TABLE t1(a, b, c)} + table t1 t1 {CREATE TABLE t1(a, b, c)} } do_catchsql_test 6.3 { diff --git a/test/tester.tcl b/test/tester.tcl index 9b8595311f..2dcbd2f0f3 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -1892,5 +1892,11 @@ set AUTOVACUUM $sqlite_options(default_autovacuum) # Make sure the FTS enhanced query syntax is disabled. set sqlite_fts3_enable_parentheses 0 +# During testing, assume that all database files are well-formed. The +# few test cases that deliberately corrupt database files should rescind +# this setting by invoking "database_can_be_corrupt" +# +database_never_corrupt + source $testdir/thread_common.tcl source $testdir/malloc_common.tcl diff --git a/test/trans2.test b/test/trans2.test index cfd3e67736..36a2f9986b 100644 --- a/test/trans2.test +++ b/test/trans2.test @@ -161,7 +161,7 @@ for {set i 2} {$i<=30} {incr i} { z = CASE WHEN id<$max_rowid THEN zeroblob((random()&65535)%5000 + 1000) END; } - } {1 {t1.z may not be NULL}} + } {1 {NOT NULL constraint failed: t1.z}} do_test trans2-$i.11 { db eval {SELECT md5sum(u1), md5sum(u2) FROM t1 ORDER BY id} } $newres @@ -185,7 +185,7 @@ for {set i 2} {$i<=30} {incr i} { z = CASE WHEN id<$max1 THEN zeroblob((random()&65535)%5000 + 1000) END; } - } {1 {t1.z may not be NULL}} + } {1 {NOT NULL constraint failed: t1.z}} do_test trans2-$i.31 { db eval {SELECT md5sum(u1), md5sum(u2) FROM t1 ORDER BY id} } $origres