python / python/cpython

sqlite3 command-line interface crashes on a NUL byte or lone surrogate in an input line

Open
#153,731 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-sqlite3 type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug description

The python -m sqlite3 interactive shell crashes with a traceback and exits
when an input line contains an embedded NUL byte, or a lone surrogate under a
surrogateescape stdin. sqlite3.complete_statement() raises ValueError
(embedded NUL) or UnicodeEncodeError (lone surrogate); neither is a
sqlite3.Error, so it escapes the REPL instead of being reported like an
ordinary error.

$ printf "SELECT '\0';\nSELECT 1;\n" | python -m sqlite3
sqlite> Traceback (most recent call last):
  ...
ValueError: embedded null character

The following SELECT 1; never runs. Invalid SQL and unknown dot-commands, by
contrast, print a clean error and keep the shell running.

CPython versions tested on

3.14, 3.15, 3.16

Operating systems tested on

macOS

Linked PRs
  • gh-153732

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported inputs through the python -m sqlite3 interactive shell and inspect how it calls sqlite3.complete_statement(). Done means NUL-byte and lone-surrogate input produce a clean error, while the shell remains running and processes the following statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
cli, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.