m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
137 stars 27 forks source link

Rekey operation does not throw an error and results in corrupt database file when in WAL mode #91

Closed titanism closed 2 months ago

titanism commented 2 months ago

Related to #64 - a rekey operation does not throw an error until you call vacuum, and when that occurs the database is stuck in a corrupt state.

Further attempts to open a database that "rekey" was invoked upon while in WAL mode fail, resulting in a corrupt database file that cannot be opened.

db.pragma('key="foo"');
db.pragma('rekey="baz"'); // <--- does not throw an error when already in WAL mode
titanism commented 2 months ago

The fix we found was to call vacuum after changing WAL to DELETE and before (and after) calling rekey

m4heshd commented 2 months ago

I'm closing this as it's the intended behavior and advised to do so. I do feel like this should go in the SQLite3MC documentation. Feel free to open an issue about it in the SQLite3MC repo if you think so.