SQLite Forum

[PATCH] Ensure sqlite3_value is a multiple of 8 in size
Login

[PATCH] Ensure sqlite3_value is a multiple of 8 in size

(1) By Mikael Pettersson (mikpelinux) on 2020-08-29 11:08:07 [source]

Running the sqlite-3.33 test suite on m68k-linux-gnu fails as follows:

make test
...
./sessionfuzz run /home/mikpe/rpmbuild/BUILD/sqlite-src-3330000/test/sessionfuzz-data1.db
sessionfuzz-data1.db: sessionfuzz: ./sqlite3.c:76425: sqlite3VdbeIntValue: Assertion `EIGHT_BYTE_ALIGNMENT(pMem)' failed.
make: *** [Makefile:1264: fuzztest] Aborted

A bisect via the git mirror showed that this started between 3.24 and 3.25 with:

From 299bf7c2f0193e2d39dd96ad4ccbe673ae9e21be Mon Sep 17 00:00:00 2001
From: drh <drh@noemail.net>
Date: Mon, 11 Jun 2018 17:35:02 +0000
Subject: [PATCH] Add the OP_SetTabCol and OP_VerifyTabCol opcodes, only when
 compiling with SQLITE_DEBUG, to do run-time verification of the column cache.

FossilOrigin-Name: b37614a3670770919a7c7f8157c5fd6578d736447998640b52e5cef8174cadc2

which contains the following:

diff --git a/src/vdbeInt.h b/src/vdbeInt.h
index dd8e29108..c883ce8b5 100644
--- a/src/vdbeInt.h
+++ b/src/vdbeInt.h
@@ -211,6 +211,9 @@ struct sqlite3_value {
   Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
   void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
 #endif
+#ifdef SQLITE_DEBUG_COLUMNCACHE
+  u32 iTabColHash;    /* Hash of table.column that is origin of this value */
+#endif
 };
 
 /*

Note the comment on pFiller.  Adding a 4-byte member to a struct that was a multiple of 8 bytes in size disables that property on platforms where the compiler doesn't require 8-byte alignments for that struct.  Linux on M68K is such a platform, as it only requires 2-byte alignment.

The following fixes the alignment issue in 3.33 on M8K, and should have no effect on other platforms (it just puts a name on the implicit tail-padding).

From 25745f8077d2bc8af7f88afffc22deedd9cbd67e Mon Sep 17 00:00:00 2001
From: Mikael Pettersson <mikpelinux@gmail.com>
Date: Thu, 27 Aug 2020 16:58:33 +0200
Subject: [PATCH] Ensure sqlite3_value is a multiple of 8 in size

---
 src/vdbeInt.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/vdbeInt.h b/src/vdbeInt.h
index 901569742..c5538794d 100644
--- a/src/vdbeInt.h
+++ b/src/vdbeInt.h
@@ -219,6 +219,7 @@ struct sqlite3_value {
 #ifdef SQLITE_DEBUG
   Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
   u16 mScopyFlags;    /* flags value immediately after the shallow copy */
+  u16 uPadding;       /* sizeof(struct sqlite3_value) must be a multiple of 8 */
 #endif
 };
 
-- 
2.25.4