Repository navigation
fix: end a running statement before clearing its bindings - #25
Merged
Merged
Conversation
A row of a running statement can point at a bound value without copying it, so clearBindings freed memory that getText and getBlob then read. Reset the statement first (JNI and Kotlin/Native): the row is refused with 'no row' instead. Adds boundary tests (invalid SQL, U+0000, lone surrogates, empty and large values, long paths, statement misuse) and close-versus-prepare/step race tests.
jvmTestAsan now also builds on Linux (clang, system OpenSSL, runtime preloaded with LD_PRELOAD) and compiles our own C with UBSan and -fno-sanitize-recover. The sanitizers workflow runs it weekly and on demand on ubuntu and fails on any finding. CONTRIBUTING lists what it covers and what it does not.
A libFuzzer harness keys a temporary or in-memory database the way the library does and runs fuzzed SQL with fuzzed text, text16 and blob parameters. Pull requests that touch the native code fuzz for five minutes with ASan and UBSan, a weekly batch runs longer. Small seed corpus and dictionary included.
pasichDev
enabled auto-merge (squash)
November 10, 2026 12:44
The base builder image ships openssl 1.1, which sqlcipher's provider does not build against. build.sh builds the pinned openssl from source, statically and with the same instrumentation as the harness.
7 tasks done
pasichDev
disabled auto-merge
November 10, 2026 13:30
…r runs A test function written as an expression returned the helper's result, which Kotlin/Native and JUnit 4 on Android reject for the whole class. The close race blocked both threads of Default on a two-core emulator, so the closer only ran after the query finished.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Bug fix.
clearBindings()on a statement whose row was still current freed a bound value that the row could point at without a copy, for exampleSELECT ?.getText/getBlobthen read freed memory: garbage text on the JVM, aheap-use-after-freeunder AddressSanitizer. A busy statement is now reset first, in both the JNI glue and Kotlin/Native. A read of the row after that throws "no row" instead of returning freed memory.Behaviour change:
clearBindings()during an iteration now ends it.Tests (
commonTest, so every target runs them):BoundaryInputTest:The regression test for the fix is
clearingBindingsWhileARowIsCurrentEndsTheRunInsteadOfLeavingTheRowDangling.CloseRaceTest: close against prepare/bind/step/reset on several threads, against a long query and against a statement close. Fixed seeds, bounded byrunTesttimeouts.Sanitizers:
jvmTestAsannow also builds on Linux, with clang and the system OpenSSL viaLD_PRELOAD.-fno-sanitize-recover=all. Over the whole build it trips a benign signed overflow inside SQLite, so SQLite is left out.sanitizers.ymlruns it weekly and on demand, and fails on any finding.Fuzzing:
.clusterfuzzlite/and a libFuzzer harnessfuzz/sealite_fuzz.cover the SQLCipher open/key/prepare/bind/step path, with a dictionary and seed corpus.fuzz-pr.yml: 300 s per sanitizer on PRs that touch native or fuzz code.fuzz-batch.yml: a weekly run.CONTRIBUTING has a new "Sanitizers and fuzzing" section with the scope and the blind spots.
How it was tested
jvmTestAsan(ASan and UBSan) on Linux arm64 in Docker (Ubuntu 24.04, clang 18): 164 passed, 0 failed. With the fix reverted, ASan reports a heap-use-after-free and the task fails.jvmTestAsanon macOS.jvmTestfor the new and related classes on macOS.build.shin Docker, run for 120 s under ASan and UBSan with no findings (~109k inputs).Not verified:
Checklist
Stringor left unwipedCHANGELOG-relevant behaviour described aboveCloses #13