Open
Description
Crash report
What happened?
The interpreter will abort if runpy._run_module_code
is called with invalid values:
import runpy
runpy._run_module_code("A", {0: ""}, "")
Another way to trigger:
class Parent:
def __dir__(self):
return [0]
class WithNonStringAttrs(Parent):
blech = None
WithNonStringAttrs().bluch
Abort message:
python: Objects/unicodeobject.c:10799: _PyUnicode_Equal: Assertion `PyUnicode_Check(str2)' failed.
Aborted (core dumped)
The suggestions machinery is the source of the issue, with calculate_suggestions
calling _PyUnicode_Equal(name, item)
for an item that might not be unicode.
Only aborts in 3.12. In 3.13 and main it results in an error in the traceback machinery:
Exception ignored in the internal traceback machinery:
Traceback (most recent call last):
File "/home/danzin/projects/upstream_cpython/Lib/traceback.py", line 139, in _print_exception_bltin
return print_exception(exc, limit=BUILTIN_EXCEPTION_LIMIT, file=file, colorize=colorize)
File "/home/danzin/projects/upstream_cpython/Lib/traceback.py", line 129, in print_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
File "/home/danzin/projects/upstream_cpython/Lib/traceback.py", line 1090, in __init__
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
File "/home/danzin/projects/upstream_cpython/Lib/traceback.py", line 1531, in _compute_suggestion_error
return _suggestions._generate_suggestions(d, wrong_name)
TypeError: all elements in 'candidates' must be strings
[...]
Will submit a PR shortly.
Found using fusil by @vstinner.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.12.8+ (heads/3.12:580d7810946, Feb 2 2025, 01:56:47) [GCC 13.3.0]
Linked PRs
Metadata
Metadata
Assignees
Labels
only security fixesonly security fixesbugs and security fixesbugs and security fixesbugs and security fixesbugs and security fixes(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)A hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump