Crash in _interpreters.create() when config string has an unpaired surrogate
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esamina Python/interpconfig.c, in particolare _config_dict_copy_str, ed esegui il riproduttore BadConfig fornito con un surrogate non appaiato. Il completamento si ottiene quando l’input solleva UnicodeEncodeError invece di causare un segfault; gh-148799 è già collegato come correzione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100