Repository navigation
fix(jdbc): reject restore on a read-only connection - #1511
Merged
Merged
Conversation
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.
restore bypasses read-only connections
Statement.execute and executeUpdate hand
restore from <file>straight to NativeDB.restore, which copies the file over the target database through the SQLite online backup API. That API writes pages via the pager and never looks at PRAGMA query_only, which is the only mechanism jdbc.explicit_readonly uses to honour Connection.setReadOnly(true). I checked this on master with an explicit read-only connection:insert into t values(9)fails with SQLITE_READONLY, yetrestore from '<other.db>'on the same statement returns normally and leaves the database holding the other file's contents (3 rows replaced by 1). With open_mode READONLY the backup step does fail, but NativeDB.restore takes its return code from the source handle, so the statement still reports success without restoring anything. The root cause is that no read-only check sits on the extended-command path at all; #1502 added tryEnforceTransactionMode to the SQL branch only, and that pragma would not have stopped the backup API either.Left as is, any code relying on a read-only connection to contain user-supplied SQL (report consoles,
@Transactional(readOnly = true)paths) can have its whole database swapped for any file the process can read. The fix rejects RestoreCommand with SQLITE_READONLY whenever conn.isReadOnly(), at both dispatch sites; backup only reads the source and is left alone. The new BackupTest case fails on master ("Expecting code to raise a throwable") and passes with the fix, the full suite is green on JDK 21 (506 tests, 13 skipped), and the changed lines match google-java-format 1.11 AOSP output. I could not run spotless:check itself because gjf 1.11 does not start on JDK 21.