Skip to content

fix: check answers for a database that a crash left with a hot journal - #28

Merged
pasichDev merged 3 commits into
mainfrom
fix/api-audit
Nov 10, 2026
Merged

pasichDev merged 3 commits into
mainfrom
fix/api-audit

Conversation

@pasichDev

Copy link
Copy Markdown
Owner

What and why

Each fix is proven by a test that failed on main:

  • Sealite.check answered nothing after a crash in the middle of a write. A hot -journal makes SQLite refuse to read the database through a read-only connection (SQLITE_READONLY_ROLLBACK, 776). check threw an SQLiteException for every key. That is exactly the situation step 4 of the documented key-storage protocol after a rekey calls it in. In that one case it now reopens read-write. SQLite rolls the unfinished transaction back, as the next open by anyone would, and check answers for the rolled-back file. A wrong key still answers WrongKey: HMAC verification fails before anything is written. The test checks the wrong key first, then the right one, then integrity_check and the committed rows. KDoc, README and Module.md no longer say check never writes.
  • JVM: an untrusted cache directory left a library directory in the temp dir on every start. When the per-user cache can't be trusted (no writable home, a symbolic link, a container UID without a passwd entry), the library is extracted to a fresh private temp directory. That directory is now deleted when the JVM exits.
  • Docs: the "Without Room" example in Module.md now closes its temporary key. The README install snippet is marked for release-please (extra-files), so a release updates its version. This is in its own commit, bdbc1a1, and can be dropped.

How it was tested

  • New tests: CheckTest.aDatabaseACrashLeftWithAHotJournalIsAnsweredForBothKeysAndRolledBack (JVM and macOS native), LoaderExitTest (child JVM, POSIX), OpenSequenceTest.aMessageReportsExactlyItsOwnCode
  • :sealite:jvmTest, the three jvmLoaderEnvTest* tasks, :sealite:macosArm64Test, koverVerify (100 %), detekt, checkLegacyAbi, dokkaGeneratePublicationHtml, spotlessCheck
  • Platforms tested: jvm (macOS), macosArm64

Not verified: Android, iOS, Windows and Linux. This PR's CI runs them.

Checklist

  • Public API unchanged (sealite/api dumps identical)
  • No key material is logged, copied into a String or left unwiped
  • Docs and CHANGELOG-relevant behaviour described above
  • New source files carry the SPDX header

SQLite refuses to read a database with a hot rollback journal through a read-only connection (SQLITE_READONLY_ROLLBACK), so Sealite.check threw an SQLiteException for every key after a crash in the middle of a write or of a rekey, which is the very situation the documented key-storage protocol calls it in. It now reopens read-write in that one case, which rolls the unfinished transaction back as any later open would, and then answers.
When the cache directory can not be trusted the library is extracted to a new temporary directory. Only the directory was registered for deletion, and a directory that still holds the library is not removed, so every start left a copy of the library behind.
@pasichDev
pasichDev enabled auto-merge (squash) November 10, 2026 13:31
@pasichDev
pasichDev merged commit 3478817 into main Nov 10, 2026
18 checks passed
@pasichDev
pasichDev deleted the fix/api-audit branch November 10, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant