In Lib/sqlite3/_completer.py, the schema name from PRAGMA database_list
is interpolated directly into an SQL string:
SELECT name || ' ' FROM \"{schema}\".sqlite_master
If a user attaches a database whose name contains a double quote, the
resulting SQL is invalid and _complete() raises OperationalError instead
of returning completion matches.
Reproduction:
import sqlite3
from sqlite3 import _completer
con = sqlite3.connect(':memory:')
con.execute('ATTACH DATABASE \':memory:\' AS \'weird"name\'')
_completer._complete(con, 'a', 0)
Output:
OperationalError unrecognized token: "".sqlite_master
WHERE name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'"
The same problem exists in the column-completion query:
JOIN pragma_table_xinfo(sm.name,'{schema}') AS pti
Suggested fix: quote the schema name as an SQL identifier, replacing
embedded double quotes with two double quotes.
Discovered while reviewing the module with an AI assistant.
Linked PRs
In Lib/sqlite3/_completer.py, the schema name from PRAGMA database_list
is interpolated directly into an SQL string:
If a user attaches a database whose name contains a double quote, the
resulting SQL is invalid and _complete() raises OperationalError instead
of returning completion matches.
Reproduction:
Output:
The same problem exists in the column-completion query:
Suggested fix: quote the schema name as an SQL identifier, replacing
embedded double quotes with two double quotes.
Discovered while reviewing the module with an AI assistant.
Linked PRs