Repository navigation
Conversation
… a backslash The SQLite read path passed IdentifierQuotingStyle::DoubleQuotes, which emits an embedded `"` as `\"` and doubles a real backslash. SQLite, like the SQL standard and like PostgreSQL, escapes `"` by doubling it and treats `\` as a literal byte, so the identifier ClickHouse sent was not the identifier SQLite parsed: `c"1` went out as `"c\"1"`, which SQLite tokenizes as the identifier `c\` followed by stray SQL, and `a\b` went out as `"a\\b"`, a different name. Reading such a table failed with SQLITE_ENGINE_ERROR. CREATE TABLE succeeded, because structure inference passes the name as a SQLite string literal, so the table was writable but never readable. Both characters are legal in SQLite identifiers, and such names are created by SQLite itself. IdentifierQuotingStyle::DoubleQuotesPostgreSQL is not a vendor quirk but the SQL-standard delimited-identifier rule, and it is byte-for-byte what SQLite requires, so this changes only which existing value the four read sites pass: the generated wrapper column list and the table-name form in StorageSQLite::read, the engine's `(SELECT ...)`/`query()` argument in registerStorageSQLite, and the same argument in TableFunctionSQLite::parseArguments. Those four sites reach exactly two dispatchers, IAST::FormatSettings::writeIdentifier and quoteExternalIdentifier, and both already implement that rule, so no enum member, helper, dispatcher or shared header changes. Fixing either dispatcher alone would have been insufficient, which the new test pins with one arm per dispatcher. The SQLite database engine references no quoting style and inherits the fix transitively. DoubleQuotes keeps its behaviour for its other consumers: the show_create_query_identifier_quoting_style setting value, Cassandra and the XDBC bridge. No setting is added or changed. This is not an injection. Reads go through sqlite3_prepare_v2, which compiles a single statement, so a mis-quoted identifier fails loudly instead of executing a statement list. The INSERT sink defect is separate. Related: ClickHouse#117421 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold
What I checked hardest, since none of it is visible in the diff:
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260920-110500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260920-102400 |
|
Workflow [PR], commit [f757c75] Summary: ❌
AI ReviewSummaryThis PR fixes SQLite read-side identifier escaping by switching the four SQLite read/query carriers to Final VerdictStatus: ✅ Approve |
CI finish ledger - 7d58ceaEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates: (a) 0 of 173 checks queued or running; (b) Session id: cron:our-pr-ci-monitor:20260920-143138 |
There was a problem hiding this comment.
The description: "This is not an injection: reads go through sqlite3_prepare_v2, which compiles a single statement, so a mis-quoted identifier fails loudly" is wrong on both halves.
SQLiteSource.cpp:53 passes pzTail == nullptr, so a trailing statement is silently ignored rather than rejected; and "only the first statement executes" does not mean that statement cannot be altered — a column named a" FROM other_table -- formatted as SELECT "a\" FROM other_table --" FROM "target", so the embedded quote rewrites the FROM clause with no semicolon involved. That is an injection primitive, and closing it is what this PR does.
|
Both halves confirmed, and I have rewritten that sentence. At source: Measured end-to-end on clean master (26.10.1.1, fix not applied), against a SQLite file holding
Row 2 is your example: the I left the changelog category at The |
CI finish ledger - d97d807Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
156 checks succeeded, 18 were skipped, Session id: cron:our-pr-ci-monitor:20260921-103829 |
|
Dear @tiandiwonder, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@groeneai is this PR still needed? A similar fix went to master recently |
|
No, it is no longer needed. #104510 switched every SQLite read site to the new |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading SQLite tables and columns whose names contain a double quote or a backslash. The
SQLitetable engine, thesqlite()table function and theSQLitedatabase engine escaped identifiers with backslashes, which SQLite does not honour inside a quoted identifier, so such a table could not be read and the query failed withSQLITE_ENGINE_ERROR; a crafted column name could instead redirect the read to another table in the same database file.Description
Related: #117421. That PR fixes the SQLite INSERT sink; this is the read path it scoped out, promised in #117421 (comment).
The four SQLite read call sites passed
IdentifierQuotingStyle::DoubleQuotes, which emits an embedded"as\"and doubles a real backslash. SQLite, like the SQL standard and PostgreSQL, escapes"by doubling it and treats\as a literal byte, so the identifier sent was not the one SQLite parsed:c"1went out as"c\"1", anda\bas"a\\b". Reading such a table failed withCode: 591 ... SQL logic error (SQLITE_ENGINE_ERROR).CREATE TABLEsucceeded, because structure inference passes the name as a literal, so after #117421 such a table is writable but never readable. Both characters are legal in SQLite identifiers.This is an identifier-injection primitive, not only an unparseable name. A column named
a" FROM other_table --went out asSELECT "a\" FROM other_table --" FROM "target", a valid statement overother_table: on master that read silently returnsother_table's rows. It stays within one statement and one file:SQLiteSource.cpp:53passespzTail == nullptr, so text after a;is discarded rather than executed, and the same DDL author can already pass arbitrary SQLite text via the(SELECT ...)andquery()forms.The fix passes
IdentifierQuotingStyle::DoubleQuotesPostgreSQLat those four sites. That enumerator is the SQL-standard delimited-identifier rule, byte-for-byte what SQLite requires, so no enum member, helper, dispatcher or shared header changes.DoubleQuotesis left untouched for its other consumers: theshow_create_query_identifier_quoting_stylesetting value, Cassandra and the XDBC bridge.The four sites reach two dispatchers,
IAST::writeIdentifierandquoteExternalIdentifier, and both needed the change, so the test isolates each with its own arm. It covers the engine table-name,(SELECT ...)andquery()forms, the table function, a pushed-downWHERE, both halves of the escaping rule, and two controls green on master.Workflow [PR]
Sync PR [sync-upstream/pr/121180]