Skip to content

Commit f8ecc2d

Browse files
committed
Fix issue with changing page size via VACUUM
Trying to change the page size for an encrypted database by issuing PRAGMA PAGE_SIZE followed by VACUUM results in a corrupted database. This has been fixed by adjusting the VACUUM procedure to ignore a page size change request for encrypted databases.
1 parent 1884875 commit f8ecc2d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

scripts/patchsqlite3.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ sed 's/sqlite3_file_control\(.*SQLITE_FCNTL_PRAGMA\)/sqlite3mcFileControlPragma\
2727
| sed '/^ if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;/a \ if( sqlite3mcPagerHasCodec(pPager) != 0 ) return 0;' \
2828
| sed '/^ }else if( USEFETCH(pPager) ){/c \ }else if( USEFETCH(pPager) && sqlite3mcPagerHasCodec(pPager) == 0 ){' \
2929
| sed '/^ if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0));/a \\n \/\* Initialize wrapper for memory management.\*\/\n if( rc==SQLITE_OK ) {\n sqlite3mcInitMemoryMethods();\n }\n' \
30-
| sed '/Lock the source database handle./i \ \/\* Check whether databases are compatible with backup \*\/\n if (!sqlite3mcIsBackupSupported(pSrcDb, zSrcDb, pDestDb, zDestDb)){\n sqlite3ErrorWithMsg(pDestDb, SQLITE_ERROR, \"backup is not supported with incompatible source and target databases\");\n return NULL;\n }\n'
30+
| sed '/Lock the source database handle./i \ \/\* Check whether databases are compatible with backup \*\/\n if (!sqlite3mcIsBackupSupported(pSrcDb, zSrcDb, pDestDb, zDestDb)){\n sqlite3ErrorWithMsg(pDestDb, SQLITE_ERROR, \"backup is not supported with incompatible source and target databases\");\n return NULL;\n }\n' \
31+
| sed '/nRes = sqlite3BtreeGetRequestedReserve(pMain)/a \\n \/\* A VACUUM cannot change the pagesize of an encrypted database. \*\/\n if( db->nextPagesize ){\n extern void sqlite3mcCodecGetKey(sqlite3*, int, void**, int*);\n int nKey;\n char *zKey;\n sqlite3mcCodecGetKey(db, iDb, (void**)&zKey, &nKey);\n if( nKey ) db->nextPagesize = 0;\n }' \

src/sqlite3patched.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156216,6 +156216,15 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
156216156216
}
156217156217
nRes = sqlite3BtreeGetRequestedReserve(pMain);
156218156218

156219+
/* A VACUUM cannot change the pagesize of an encrypted database. */
156220+
if( db->nextPagesize ){
156221+
extern void sqlite3mcCodecGetKey(sqlite3*, int, void**, int*);
156222+
int nKey;
156223+
char *zKey;
156224+
sqlite3mcCodecGetKey(db, iDb, (void**)&zKey, &nKey);
156225+
if( nKey ) db->nextPagesize = 0;
156226+
}
156227+
156219156228
sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
156220156229
sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
156221156230
sqlite3BtreeSetPagerFlags(pTemp, pgflags|PAGER_CACHESPILL);

0 commit comments

Comments
 (0)