aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-03-03 18:35:00 +0000
committerdrh <>2023-03-03 18:35:00 +0000
commit1b9db7f32de952d7c88a87b8251b005ee08f3d65 (patch)
tree835adb23e240e7451e78e28279a1e8b9db035b91 /src
parent04337898635b3048691b795f2f1922b3fda2ddc9 (diff)
downloadsqlite-1b9db7f32de952d7c88a87b8251b005ee08f3d65.tar.gz
sqlite-1b9db7f32de952d7c88a87b8251b005ee08f3d65.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/pragma.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/pragma.c b/src/pragma.c
index 522a12d33..01c2d486e 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;