Crash report
What happened?
imp-name.py:
import sys, types
name = 'mod\ud800'
sys.modules[name] = types.ModuleType(name)
a = __import__(name)
print(a)
Normal:
$> ./python.exe imp-name.py
<module 'mod\ud800'>
With importtime=2:
$> ./python.exe -X importtime=2 imp-name.py
import time: self [us] | cumulative | imported package
...
import time: 16878 | 20452 | _colorize
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in position 3: surrogates not allowed
The above exception was the direct cause of the following exception:
SystemError: <built-in function __import__> returned a result with an exception set
Current thread 0x0000000201fb75c0 (most recent call first):
File "~/src/tp/cpython/imp-name.py", line 6 in <module>
fish: Job 1, './python.exe -X importtime=2 im…' terminated by signal SIGABRT (Abort)
$ [SIGABRT]>
The code in import.c:
|
#define import_level FIND_AND_LOAD(interp).import_level |
|
fprintf(stderr, "import time: cached | cached | %*s\n", |
|
import_level*2, PyUnicode_AsUTF8(name)); |
|
#undef import_level |
Passes PyUnicode_AsUTF8(name) directly to fprintf without checking if the conversion/view was successful or not. This causes either a segfaul, or an abort depending on the libc.
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
Crash report
What happened?
imp-name.py:
Normal:
With importtime=2:
The code in import.c:
cpython/Python/import.c
Lines 325 to 328 in 228b1bf
Passes
PyUnicode_AsUTF8(name)directly to fprintf without checking if the conversion/view was successful or not. This causes either a segfaul, or an abort depending on the libc.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