diff --git a/BUILD.gn b/BUILD.gn index 3b03c3791046de8e2318c198c969cf877be217e9..d796c2289a89b6f149cb1557281a458bfb528ff9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -244,6 +244,7 @@ if (is_mingw || is_mac) { cflags = [ "-Wno-error=implicit-function-declaration", "-Wno-implicit-fallthrough", + "-Wno-inconsistent-dllimport", ] part_name = "sqlite" subsystem_name = "thirdparty" diff --git a/patch/0007-Rekey-is-prohibited-in-multi-process-scenarios.patch b/patch/0007-Rekey-is-prohibited-in-multi-process-scenarios.patch new file mode 100644 index 0000000000000000000000000000000000000000..832ddf59ea613ee5c9812becc711036f881b1d1d --- /dev/null +++ b/patch/0007-Rekey-is-prohibited-in-multi-process-scenarios.patch @@ -0,0 +1,116 @@ +From dcd58e24c29a5a4bbda63291ea82a39724c334bb Mon Sep 17 00:00:00 2001 +From: bjd +Date: Tue, 29 Apr 2025 10:39:11 +0800 +Subject: [PATCH] Rekey is prohibited in multi-process scenarios + +Signed-off-by: bjd +--- + src/sqlite3.c | 64 +++++++++++++++++++++++++++++++++++++-------------- + 1 file changed, 47 insertions(+), 17 deletions(-) + +diff --git a/src/sqlite3.c b/src/sqlite3.c +index 7e9dcbf..183d75b 100644 +--- a/src/sqlite3.c ++++ b/src/sqlite3.c +@@ -259832,7 +259832,12 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ + } + + sqlite3_mutex_leave(db->mutex); +- ++ rc = sqlite3BtreeBeginTrans(p, 0, 0); ++ if( rc!=SQLITE_OK ){ ++ sqlite3_log(SQLITE_WARNING, "sqlite3CodecAttach: error when begin trans. errno = %d", rc); ++ return rc; ++ } ++ sqlite3BtreeCommit(p); + return SQLITE_OK; + } + +@@ -259874,6 +259879,21 @@ int sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey){ + return sqlite3_rekey_v2(db, "main", pKey, nKey); + } + ++static inline u8 IsConnectionValidForCheck(Pager *pPager) ++{ ++#if SQLITE_OS_UNIX ++ unixFile *fd = (unixFile *)pPager->fd; ++ // unix and only one connection exist ++ if (fd == NULL || fd->pInode == NULL || pPager->pVfs == NULL || ++ sqlite3_stricmp(pPager->pVfs->zName, "unix") != 0 || fd->pInode->nRef != 1) { ++ return 0; ++ } ++ return 1; ++#else ++ return 0; ++#endif ++} ++ + int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ + if(db == NULL || pKey == NULL || nKey == 0){ + return SQLITE_ERROR; +@@ -259898,7 +259918,27 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ + return rc; + } + sqlite3_mutex_enter(db->mutex); +- (void)sqlite3BtreeBeginTrans(p, 1, 0); ++ rc = sqlite3BtreeBeginTrans(p, 1, 0); ++ if(rc != SQLITE_OK){ ++ sqlite3_mutex_leave(db->mutex); ++ sqlite3_log(SQLITE_WARNING, "sqlite3_rekey_v2: error when begin trans. errno = %d.", rc); ++ return rc; ++ } ++#if SQLITE_OS_UNIX && !defined(SQLITE_OMIT_WAL) ++ if(pPager->pWal != NULL){ ++ rc = unixShmSystemLock((unixFile *)pPager->fd, F_WRLCK, UNIX_SHM_DMS, 1); ++ if(rc != SQLITE_OK || !IsConnectionValidForCheck(pPager)){ ++ sqlite3_log(SQLITE_WARNING, "sqlite3_rekey_v2: error when lock. errno = %d.", rc); ++ if(rc == SQLITE_OK){ ++ unixShmSystemLock((unixFile *)pPager->fd, F_RDLCK, UNIX_SHM_DMS, 1); ++ rc = SQLITE_BUSY; ++ } ++ (void)sqlite3BtreeRollback(p, SQLITE_ABORT_ROLLBACK, 0); ++ sqlite3_mutex_leave(db->mutex); ++ return rc; ++ } ++ } ++#endif + sqlite3PagerPagecount(pPager, &pageCount); + // support hmac algo changed by using rekey operation + int oldHmacAlgo = ctx->writeCtx->codecConst.hmacAlgo; +@@ -259922,6 +259962,11 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ + } + } + } ++#if SQLITE_OS_UNIX && !defined(SQLITE_OMIT_WAL) ++ if(pPager->pWal != NULL){ ++ unixShmSystemLock((unixFile *)pPager->fd, F_RDLCK, UNIX_SHM_DMS, 1); ++ } ++#endif + if(rc == SQLITE_OK){ + (void)sqlite3BtreeCommit(p); + sqlite3CodecFreeKeyContext(ctx->readCtx); +@@ -261257,21 +261302,6 @@ CHK_RESTORE_OUT: + return rc; + } + +-static inline u8 IsConnectionValidForCheck(Pager *pPager) +-{ +-#if SQLITE_OS_UNIX +- unixFile *fd = (unixFile *)pPager->fd; +- // unix and only one connection exist +- if (fd == NULL || fd->pInode == NULL || pPager->pVfs == NULL || +- sqlite3_stricmp(pPager->pVfs->zName, "unix") != 0 || fd->pInode->nRef != 1) { +- return 0; +- } +- return 1; +-#else +- return 0; +-#endif +-} +- + static int MetaDwrOpenAndCheck(Btree *pBt) + { + Pager *pPager = pBt->pBt->pPager; +-- +2.46.2.windows.1 + diff --git a/patch/0007-BugFix-CurrVersion.patch b/patch/0008-BugFix-CurrVersion.patch similarity index 86% rename from patch/0007-BugFix-CurrVersion.patch rename to patch/0008-BugFix-CurrVersion.patch index 36d5eac8bfb289677e2bf1055a315f764e5c1464..31828889b44739d17518b2eb4ac7500327d0c7ec 100644 --- a/patch/0007-BugFix-CurrVersion.patch +++ b/patch/0008-BugFix-CurrVersion.patch @@ -1,14 +1,15 @@ -From 4cb905b575c2103caada8386cb5fe35562059d4a Mon Sep 17 00:00:00 2001 -From: ryne3366 -Date: Mon, 24 Mar 2025 20:30:45 +0800 -Subject: [PATCH] check permission for meta file +From d67dfe05906da2b4f4699e1a46c99adef762fa91 Mon Sep 17 00:00:00 2001 +From: bjd +Date: Tue, 29 Apr 2025 10:55:16 +0800 +Subject: [PATCH] 08 +Signed-off-by: bjd --- - src/sqlite3.c | 120 ++++++++++++++++++++++++++++++++++++++++---------- - 1 file changed, 96 insertions(+), 24 deletions(-) + src/sqlite3.c | 122 +++++++++++++++++++++++++++++++++++++++----------- + 1 file changed, 96 insertions(+), 26 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 7e9dcbf..d350cfc 100644 +index 183d75b..ad17f02 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -45151,7 +45151,7 @@ static int unixOpen( @@ -42,7 +43,16 @@ index 7e9dcbf..d350cfc 100644 } /* If no error occurred, set the output variables. */ -@@ -205751,6 +205757,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ +@@ -139303,8 +139309,6 @@ static const sqlite3_api_routines sqlite3Apis = { + sqlite3_set_clientdata, + #ifdef SQLITE_ENABLE_DROPTABLE_CALLBACK + sqlite3_set_droptable_handle +-#else +- 0 + #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ + }; + +@@ -205751,6 +205755,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ return rc; } @@ -82,7 +92,7 @@ index 7e9dcbf..d350cfc 100644 /* ** Implementation of offsets() function. */ -@@ -205787,6 +205826,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( +@@ -205787,6 +205824,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( sCtx.iDocid = pCsr->iPrevId; sCtx.pCsr = pCsr; @@ -95,7 +105,7 @@ index 7e9dcbf..d350cfc 100644 /* Loop through the table columns, appending offset information to ** string-buffer res for each column. */ -@@ -260390,7 +260435,7 @@ static int PragmaMetaDoubleWrie(sqlite3 *db, int iDb, Parse *parse, const char * +@@ -260435,7 +260478,7 @@ static int PragmaMetaDoubleWrie(sqlite3 *db, int iDb, Parse *parse, const char * sqlite3_mutex_enter(db->mutex); // only support enabled meta double write int rc = MetaDwrOpenAndCheck(pBt); @@ -104,7 +114,7 @@ index 7e9dcbf..d350cfc 100644 parse->nErr++; parse->rc = rc; } -@@ -260842,6 +260887,29 @@ static inline const char *GetMetaFilePath(Pager *pPager) +@@ -260887,6 +260930,29 @@ static inline const char *GetMetaFilePath(Pager *pPager) return pPager->metaFd == NULL ? NULL : ((const char *)pPager->metaFd + ROUND8(pPager->pVfs->szOsFile)); } @@ -134,7 +144,7 @@ index 7e9dcbf..d350cfc 100644 static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { if (pPager->metaFd || pPager->zFilename == NULL) { return SQLITE_OK; -@@ -260858,15 +260926,10 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { +@@ -260903,15 +260969,10 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { return SQLITE_NOMEM_BKPT; } sqlite3_snprintf(size, metaPath, "%s-dwr", pPager->zFilename); @@ -151,7 +161,7 @@ index 7e9dcbf..d350cfc 100644 u32 flags = (SQLITE_OPEN_READWRITE | SQLITE_OPEN_SUPER_JOURNAL); if (openCreate) { flags |= SQLITE_OPEN_CREATE; -@@ -261425,16 +261488,6 @@ static inline void MarkLockStatusByRc(int rc, u32 lockIdx, u32 lockLen, u8 lockT +@@ -261455,16 +261516,6 @@ static inline void MarkLockStatusByRc(int rc, u32 lockIdx, u32 lockLen, u8 lockT } } @@ -168,7 +178,7 @@ index 7e9dcbf..d350cfc 100644 static inline const char *IdxToLockName(u32 idx) { const char *lockName[MAX_LOCK_NUM] = {"write", "ckpt", "recover", "read0", -@@ -261451,7 +261504,7 @@ static void DumpHandleLock(char *dumpBuf, int dumpBufLen) +@@ -261481,7 +261532,7 @@ static void DumpHandleLock(char *dumpBuf, int dumpBufLen) for (int i = 0; i < MAX_LOCK_NUM && availLen > DUMP_MAX_STR_LEN; i++) { if (lockStatus[i] != NO_LOCK) { tmp[0] = '\0'; @@ -177,7 +187,7 @@ index 7e9dcbf..d350cfc 100644 int len = strlen(tmp); tmp += len; availLen -= len; -@@ -261490,8 +261543,8 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) +@@ -261520,8 +261571,8 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) sqlite3_log(SQLITE_ERROR, "[SQLite]Inode is null!"); return; } @@ -188,7 +198,7 @@ index 7e9dcbf..d350cfc 100644 const char *lockName[DB_LOCK_NUM] = {"pending", "reserved", "shared_first"}; char *tmp = dumpBuf; int availLen = dumpBufLen - 1; -@@ -261511,10 +261564,13 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) +@@ -261541,10 +261592,13 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) static void DumpWalLocks(unixFile *file, u8 walEnabled, char *dumpBuf, int dumpBufLen) { @@ -204,7 +214,7 @@ index 7e9dcbf..d350cfc 100644 unixShmNode *pShmNode = file->pShm->pShmNode; char *tmp = dumpBuf; int availLen = dumpBufLen - 1; -@@ -261583,6 +261639,22 @@ static void DumpLocksByPager(Pager *pPager) +@@ -261613,6 +261667,22 @@ static void DumpLocksByPager(Pager *pPager) } #endif /* SQLITE_OS_UNIX */ @@ -228,5 +238,5 @@ index 7e9dcbf..d350cfc 100644 #ifdef SQLITE_EXPORT_SYMBOLS #ifndef SQLITE_CKSUMVFS_STATIC -- -2.34.1 +2.46.2.windows.1