python / python/cpython

concurrent.interpreters: crash (NULL dereference) when an unpickled AttributeError has a non-string arg

Aperta
#151,862 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.14 3.15 3.16 interpreter-core topic-subinterpreters type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Python/crossinterp.c's check_missing___main___attr() passes the result of PyUnicode_AsUTF8() straight to strncmp() without a NULL check:

const char *err = PyUnicode_AsUTF8(msgobj);
// Check if it's a missing __main__ attr.
int cmp = strncmp(err, "module '__main__' has no attribute '", 36);

msgobj is args[0] of an AttributeError raised on the receive side of the cross-interpreter pickle fallback, reached when an object is moved between interpreters through a concurrent.interpreters queue or channel and its unpickling in the receiving interpreter fails.

PyUnicode_AsUTF8() returns NULL (and sets an exception) when args[0] is not a str — e.g. AttributeError(42), AttributeError(b'x'), AttributeError(None) — or is a str containing lone surrogates (AttributeError('\ud800')). When err == NULL, strncmp(NULL, ...) dereferences NULL and the interpreter crashes (SIGSEGV).

Reproduction

Put an object into a concurrent.interpreters queue whose unpickling on the receive side raises an AttributeError with a non-string (or surrogate) first argument, then get() it — the receiving interpreter segfaults instead of raising NotShareableError. A self-contained reproduction is added as a regression test (test_get_unpickle_fails_with_bad_attributeerror_arg in Lib/test/test_interpreters/test_queues.py), exercising args 42, b'x', None, and '\ud800'.

Scope

This is the check_missing___main___attr() NULL dereference reached through the queue/channel receive path. It does not by itself make every cross-interpreter unpickle failure safe — Interpreter.call() has a separate crash on its result-preserve path that I will report independently.

Fix

Add a NULL guard immediately after PyUnicode_AsUTF8, matching the correctly-checked sibling helper _copy_string_obj_raw(): on NULL, clear the exception (the function asserts !PyErr_Occurred() on entry), Py_DECREF(msgobj), and return 0 (not a missing-__main__ attribute).

Affected versions

concurrent.interpreters (PEP 734) is public in 3.14+; this reproduces on main and 3.14.

Linked PR

A PR follows.

Linked PRs
  • gh-151863

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

La issue indica Python/crossinterp.c e check_missing___main___attr(); confronta la gestione di PyUnicode_AsUTF8() con quella dell’helper omologo _copy_string_obj_raw(). Esegui Lib/test/test_interpreters/test_queues.py, in particolare test_get_unpickle_fails_with_bad_attributeerror_arg, e verifica che gli argomenti AttributeError malformati elencati generino NotShareableError senza causare un crash. Una PR collegata, gh-151863, indica che il lavoro è già in corso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, python
Ambito
compilers
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.