Repository navigation
fix: read WAL-mode SQLite databases (0.4.1) - #53
Conversation
The SQLite parser loads a DB from its main-file byte image via read-only deserialize. A WAL-mode database carries read-version 2 in its file header (byte 19), and SQLite refuses to open such an image read-only without the -wal companion (absent in a byte stream) — failing with "unable to open database file" (SQLITE_CANTOPEN). The main image of a checkpointed WAL DB is a complete valid database, so reinterpret it as legacy (read-version 1) on a private copy and read its checkpointed state. Read-only; bytes never written back. Byte 18 (write version) does not gate reads, so only byte 19 is touched. Unblocks the common case: most production .db files (browsers, peewee/yfinance, many apps) default to WAL. Found by dogfooding real on-disk databases — four real WAL DBs that returned CANTOPEN now read. Gate: proptest + cargo-mutants 0-missed on sqlite.rs (12 mutants, 9 caught, 3 unviable). New test simulates a WAL header (flip read-version to 2) and asserts the parser still reads the checkpointed image. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 37 minutes and 34 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bug
The SQLite parser failed on WAL-mode databases with
failed to parse sqlite input: ... unable to open database file. Found by dogfooding real on-disk.dbfiles (yfinance, GNOME tracker, webkit) — most production databases default to WAL.Root cause
The parser loads a DB from its main-file byte image via SQLite's read-only
deserialize. A WAL-mode database carries read-version2in its file header (byte 19); SQLite refuses to open such an image read-only without the-walcompanion — which never travels in a byte stream — returningSQLITE_CANTOPEN. Empirically isolated to byte 19:write=2,read=1reads fine,read=2fails.Fix
The main image of a checkpointed WAL database is itself a complete, valid database. The parser now reinterprets it as legacy (read-version
1) on a private copy and reads its checkpointed state. Read-only — the bytes are never written back, and only byte 19 (which gates reads) is touched.Verification
Four real WAL databases that returned
CANTOPENnow read (tkr-tz 34 rows, cookies 1 row, tracker meta.db 7 rows, …); a non-WAL.sqlitestill reads; a genuinely non-SQLite.db(GNU dbm) is still honestly rejected (file is not a database).Gate
proptest+cargo-mutants0 missed onsqlite.rs(12 mutants, 9 caught, 3 unviable). New test flips a valid fixture's read-version to 2 (simulating WAL) and asserts the parser still reads it.🤖 Generated with Claude Code