Repository navigation
cold-store: repair filter for libsql /dump's unescaped virtual-table schema literals (#1391) - #1398
Conversation
…te_schema literals (#1391)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57a6aabf5d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if line.lstrip().startswith(SCHEMA_INSERT): | ||
| if line.rstrip(b"\r\n").endswith(STATEMENT_END): | ||
| out.write(repair_chunk(line)) |
There was a problem hiding this comment.
Track SQL literal boundaries before recognizing schema inserts
When a text column contains multiline SQL, this check can mistake a line inside the dumped data literal for a schema statement and rewrite it. For example, dumping a text value containing a newline followed by INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES("table","t","t",0,'CREATE VIRTUAL TABLE t USING fts5(x)'); produces a valid dump, but this filter changes the escaped quotes around the embedded CREATE statement and restoration then fails with near "CREATE": syntax error. Because the filter now runs on every export, previously exportable databases containing such text lose their backups. Track whether the stream is inside a string literal or another statement before treating a line as a repair candidate.
Useful? React with 👍 / 👎.
What
Implements the workaround documented in #1391: a streaming repair filter between the Turso
/dumpdownload and thesqlite3 -bailrebuild inscripts/export-turso.sh.libsql registers virtual tables via
INSERT INTO sqlite_schema(...)inside awritable_schemablock, emitting the embedded SQL verbatim — single quotes (an FTS5content='chunks'is the common case) are not doubled, so the literal terminates early and every stock SQLite parser fails withnear "chunks": syntax error. Any database with a quoted virtual-table definition (found live onatlas, 2026-10-27) could never be filed.How
scripts/repair_dump.py: a line-oriented, constant-memory filter (buffers only the current candidate statement, which ends at a line ending in');). All lines pass through byte-identical exceptINSERT INTO sqlite_schema(...)statements whose final SQL literal is verifiably mis-escaped — parse-based detection: the literal, read with proper''escaping, must close exactly at the statement's final quote; if it closes early or never closes, the raw SQL between the opening quote and the closing');is re-emitted with every'doubled, and the rewrite is re-parsed before being emitted (anything that does not verify passes through unchanged). Correctly-escaped statements and quote-free SQL pass through untouched.export-turso.sh: download → repair filter → truncation guard (now applied to the filtered stream; the filter passes the trailingCOMMIT;through undisturbed) →sqlite3 -bailrebuild → integrity/≥1-user-table checks, exactly as cold-store: harden turso export for GB-class databases #1383 left them. Per-DB failure isolation unchanged.Tests
TestTursoExportScript(fake-server): a newatlas-shaped fixture — FTS5 external-content table registered by the exact brokenwritable_schemaINSERT, plus its shadow tables and real FTS index rows — files successfully; the built.dbhas the virtual table insqlite_masterwith its SQL exactly as authored, and a fresh-connectionMATCH 'hello'returns the seeded row. A correctly-escaped variant files with identical registered SQL.TestDumpRepairFilter(unit): broken literal → exactly the doubled-quote form; correctly-escaped, quote-free, and unrelated input byte-identical; an unterminated statement at EOF flushes unchanged for the caller's truncation guard.pkgs/cold-store-reapersuite green; shellcheck shows only the pre-existing SC2310 infos; shfmt-i 2 -sand ruff format clean.Refs #1391
Need help on this PR? Tag
@codesmith-botwith what you need.