From: drh <> Date: Fri, 3 Mar 2023 18:35:00 +0000 (+0000) Subject: Enhance PRAGMA integrity_check so that it can detect when there are extra X-Git-Tag: version-3.42.0~294 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1b9db7f32de952d7c88a87b8251b005ee08f3d65;p=thirdparty%2Fsqlite.git Enhance PRAGMA integrity_check so that it can detect when there are extra bytes at the end of an index record, which might cause OP_IdxRowid to malfunction. dbsqlfuzz c1aa3986534d5feab8d21f28b3c1712df2ef358ba. Test case in TH3. FossilOrigin-Name: f418bdd627e84e7d494f730d7124d8f4846ebcde031f5b2498685c9aceebb3c8 --- diff --git a/manifest b/manifest index 885ee87a21..2a63a4cbbf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sit\sis\sknown\swhen\spreparing\sa\sstatement\sthat\sX\scannot\sbe\sNULL,\stransform\sthe\sexpression\s(X\sIS\sNULL)\sto\sinteger\svalue\s1\sinstead\sof\s'true'.\sThis\sis\sbecause\sunder\ssome\scircumstances,\s"Y\sIS\sTRUE"\smay\snot\sbe\sequivalent\sto\s"Y\sIS\s1". -D 2023-03-03T16:25:18.921 +C Enhance\sPRAGMA\sintegrity_check\sso\sthat\sit\scan\sdetect\swhen\sthere\sare\sextra\nbytes\sat\sthe\send\sof\san\sindex\srecord,\swhich\smight\scause\sOP_IdxRowid\sto\nmalfunction.\s\sdbsqlfuzz\sc1aa3986534d5feab8d21f28b3c1712df2ef358ba.\s\sTest\scase\nin\sTH3. +D 2023-03-03T18:35:00.504 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -616,7 +616,7 @@ F src/parse.y 960d2da92a23f8ba2ca22748a51bd75ee2c575564f2cbc59f119640e7f5b4c5d F src/pcache.c f4268f7f73c6a3db12ce22fd25bc68dc42315d19599414ab1207d7cf32f79197 F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c dee95e3cd2b61e6512dc814c5ab76d5eb36f0bfc9441dbb4260fccc0d12bbddc -F src/pragma.c 82d5090a35eac75876d3b41f48d06b2370553c9576bf2942233c462e03eb94c9 +F src/pragma.c e698baae96396cac8ff55afef1c0b84632a4b825548bf98f0c4fd1e0a90ed4bc F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c ce87a08cfddd45a147150db34190b1986f2d4a0e0828858cb6bd908c78fb02e3 F src/printf.c fb31597cf93200eba9167573094ee312b0d51b2c1998613284ceb2c8c212b492 @@ -2048,8 +2048,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e95439119ac200cb47d0e277622f41ee7986b364487cd252b485ce5fa030d70f -R 832f5112357909076c536cf7b9bea8b8 -U dan -Z 3d9689df10ad73a0297a8e055e1db782 +P cc4bb05b3653e9502b95ea6fe0bfb77feebc11285b66e1dde4c7b945928efbf1 +R e3264926b184a1150ff1e42cc58b6e34 +U drh +Z 4bf4a9f38f38c1a43669629bffba2cbf # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e32a6d4fc1..d79799f154 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cc4bb05b3653e9502b95ea6fe0bfb77feebc11285b66e1dde4c7b945928efbf1 \ No newline at end of file +f418bdd627e84e7d494f730d7124d8f4846ebcde031f5b2498685c9aceebb3c8 \ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 522a12d331..01c2d486e7 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1987,6 +1987,23 @@ void sqlite3Pragma( jmp4 = integrityCheckResultRow(v); sqlite3VdbeJumpHere(v, jmp2); + /* The OP_IdxRowid opcode is an optimized version of OP_Column + ** that extracts the rowid off the end of the index record. + ** But it only works correctly if index record does not have + ** any extra bytes at the end. Verify that this is the case. */ + if( HasRowid(pTab) ){ + int jmp7; + sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur+j, 3); + jmp7 = sqlite3VdbeAddOp3(v, OP_Eq, 3, 0, r1+pIdx->nColumn-1); + VdbeCoverage(v); + sqlite3VdbeLoadString(v, 3, + "rowid not at end-of-record for row "); + sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); + sqlite3VdbeLoadString(v, 4, " of index "); + sqlite3VdbeGoto(v, jmp5-1); + sqlite3VdbeJumpHere(v, jmp7); + } + /* Any indexed columns with non-BINARY collations must still hold ** the exact same text value as the table. */ label6 = 0;