Skip to content

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

Description

@tonghuaroot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-sqlite3type-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions