python / python/cpython

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

Open
#156,121 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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

Start in Python/crossinterp.c at check_missing___main___attr, as identified in the report, and reproduce both the lone-surrogate and non-string AttributeError cases. Verify that malformed exception arguments no longer cause a segfault and that the existing cross-interpreter call behavior remains intact; gh-156128 is already linked to this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.