python / python/cpython

Crash in _interpreters.create() when config string has an unpaired surrogate

Open
#148,798 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core topic-subinterpreters type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Crash Report

Crash description

_interpreters.create() segfaults when the config object exposes a string attribute (e.g. gil) containing an unpaired surrogate. The C helper _config_dict_copy_str calls PyUnicode_AsUTF8() and passes the result straight to strncpy() without a NULL check. When the string can't be UTF-8 encoded, PyUnicode_AsUTF8() returns NULL and sets UnicodeEncodeError, but the NULL then reaches strncpy and the interpreter crashes.

Lone surrogates are reachable from pure Python ('\udc80', chr(0xDC80)), and also show up naturally via surrogateescape — e.g. filenames, env vars, or argv with non-UTF-8 bytes that get forwarded into a config dict.

Related precedent: gh-126221 (same module, same module crash class from pure Python input).

Reproducer

import _interpreters

class BadConfig:
    use_main_obmalloc = False
    allow_fork = False
    allow_exec = False
    allow_threads = False
    allow_daemon_threads = False
    check_multi_interp_extensions = False
    own_gil = True
    gil = 'own\udc80'

_interpreters.create(BadConfig())

Expected: UnicodeEncodeError.
Actual: segfault (exit 139).

Reproduced on 3.14.3 and current main.

Error messages

zsh: segmentation fault  python3 repro.py

Your environment

  • CPython 3.14.3 and main (Python/interpconfig.c unchanged since gh-117170)
  • macOS / Linux (encoding-independent; the bug is in C)

Linked PRs

(fix ready, will link once this is filed)

Linked PRs
  • gh-148799

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

Inspect Python/interpconfig.c, especially _config_dict_copy_str, and run the supplied BadConfig reproducer with an unpaired surrogate. Completion means the input raises UnicodeEncodeError rather than segfaulting; gh-148799 is already linked as the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
compilers
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.