crossinterp: Segfault in `check_missing___main___attr` if AttributeError args are not normal
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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:
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em Python/crossinterp.c, em check_missing___main___attr, conforme identificado no relatório, e reproduza tanto o caso de AttributeError com lone-surrogate quanto o caso de AttributeError com um argumento que não seja uma string. Verifique se argumentos de exceção malformados não causam mais um segfault e se o comportamento existente das chamadas cross-interpreter permanece intacto; gh-156128 já está vinculado a esta issue.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- c, python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100