python / python/cpython

crossinterp: Segfault in `check_missing___main___attr` if AttributeError args are not normal

Aperta
#156,121 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

extension-modules topic-subinterpreters type-crash
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Crash report

What happened?

crossinterp doesn't do much checking on the arguments of the passed-in exception, allowing lone surrogate unicode, or non-str arguments cause segfaults:

Lone surrogate example:

from concurrent import interpreters
import __main__

x = 1

def f():
    return x  # forces pickle fallback

f.__name__ = f.__qualname__ = "\ud800"
setattr(__main__, "\ud800", f)

interp = interpreters.create()
interp.call(f)
> ./python.exe temp/crossinterp.py
fish: Job 1, './python.exe temp/crossinterp.py' terminated by signal SIGSEGV (Address boundary error)

Non-str argument example (a bit more convoluted):

from concurrent import interpreters

x = 1

def f():
    return x  # forces pickle fallback

interp = interpreters.create()
interp.exec("""
import pickle

def loads(data):
    raise AttributeError(42)

pickle.loads = loads
""")
interp.call(f)
> ./python.exe temp/crossinterp-2.py
fish: Job 1, './python.exe temp/crossinterp-2…' terminated by signal SIGSEGV (Address boundary error)

This is because check_missing___main___attr doesn't check the result of PyUnicode_AsUTF8 before passing it to strncmp, so if the object is not a PyUnicode object or if it can't be converted to utf8, you get a crash:

https://github.com/python/cpython/blob/91d71dd67074d4599b6bd49cc933f41f8bd57058/Python/crossinterp.c#L666-669

The fix should cover both cases, I guess:

A PyUnicode_Check on msgobj, and then a check that the PyUnicode_AsUTF8 return is valid.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Output from running 'python -VV' on the command line:

Python 3.16.0a0 (heads/main:e8158d1a02d, Aug 20 2026, 15:09:24) [Clang 21.0.0 (clang-2100.3.27.1)]

Linked PRs
  • gh-156128

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

Inizia in Python/crossinterp.c, in check_missing___main___attr, come identificato nel report, e riproduci sia il caso di AttributeError con lone-surrogate sia il caso di AttributeError con un argomento non stringa. Verifica che gli argomenti di eccezione malformati non causino più un segfault e che il comportamento esistente delle chiamate cross-interpreter rimanga invariato; gh-156128 è già collegato a questo issue.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.