Skip to content

Assertion failure from __lazy_import__(b"") #145058

@devdanzin

Description

@devdanzin

Crash report

What happened?

It's possible to make the interpreter abort by calling __lazy_import__() on a bytes object (edit: actually on any non-string objects):

__lazy_import__(b"")

Backtrace:

python: ./Include/cpython/unicodeobject.h:297: PyUnicode_GET_LENGTH: Assertion `PyUnicode_Check(op)' failed.

Program received signal SIGABRT, Aborted.

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (threadid=<optimized out>, signo=6) at ./nptl/pthread_kill.c:89
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:100
#3  0x00007ffff7445e2e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff7428888 in __GI_abort () at ./stdlib/abort.c:77
#5  0x00007ffff74287f0 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=<optimized out>, function=<optimized out>) at ./assert/assert.c:118
#6  0x00007ffff743c19f in __assert_fail (assertion=<optimized out>, file=<optimized out>, line=<optimized out>, function=<optimized out>) at ./assert/assert.c:127
#7  0x0000555555d47486 in PyUnicode_GET_LENGTH (op=op@entry=0x555556862c10 <_PyRuntime+63088>) at ./Include/cpython/unicodeobject.h:297
#8  0x0000555555d4cd51 in get_abs_name (tstate=tstate@entry=0x5555568ab628 <_PyRuntime+360584>, name=name@entry=0x555556862c10 <_PyRuntime+63088>, globals=globals@entry=0x7c7ff66885c0,
    level=level@entry=0) at Python/import.c:4157
#9  0x0000555555d566f0 in _PyImport_LazyImportModuleLevelObject (tstate=tstate@entry=0x5555568ab628 <_PyRuntime+360584>, name=name@entry=0x555556862c10 <_PyRuntime+63088>,
    builtins=<optimized out>, globals=globals@entry=0x7c7ff66885c0, locals=locals@entry=0x7c7ff66885c0, fromlist=fromlist@entry=0x0, level=<optimized out>) at Python/import.c:4471
#10 0x0000555555c61626 in builtin___lazy_import___impl (module=module@entry=0x7ccff65e6450, name=name@entry=0x555556862c10 <_PyRuntime+63088>, globals=0x7c7ff66885c0, globals@entry=0x0,
    locals=0x7c7ff66885c0, locals@entry=0x0, fromlist=fromlist@entry=0x0, level=level@entry=0) at Python/bltinmodule.c:340
#11 0x0000555555c61a79 in builtin___lazy_import__ (module=<optimized out>, args=<optimized out>, args@entry=0x7bfff5331848, nargs=nargs@entry=1, kwnames=kwnames@entry=0x0)
    at Python/clinic/bltinmodule.c.h:205
#12 0x0000555555a9df23 in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7c7ff66364c0, args=0x7bfff5331848, nargsf=<optimized out>, kwnames=0x0) at Objects/methodobject.c:465
#13 0x00005555559e658b in _PyObject_VectorcallTstate (tstate=0x5555568ab628 <_PyRuntime+360584>, callable=callable@entry=0x7c7ff66364c0, args=args@entry=0x7bfff5331848,
    nargsf=9223372036854775809, kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:136
#14 0x00005555559e667e in PyObject_Vectorcall (callable=callable@entry=0x7c7ff66364c0, args=args@entry=0x7bfff5331848, nargsf=<optimized out>, kwnames=kwnames@entry=0x0)
    at Objects/call.c:327
#15 0x0000555555c6f450 in _Py_VectorCallInstrumentation_StackRefSteal (callable=..., callable@entry=..., arguments=arguments@entry=0x7e8ff65e5280, total_args=total_args@entry=1,
    kwnames=..., kwnames@entry=..., call_instrumentation=call_instrumentation@entry=false, frame=frame@entry=0x7e8ff65e5220, this_instr=<optimized out>, tstate=<optimized out>)
    at Python/ceval.c:769
#16 0x0000555555c7f44d in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7e8ff65e5220, throwflag=<optimized out>) at Python/generated_cases.c.h:1817
#17 0x0000555555cb7ba5 in _PyEval_EvalFrame (tstate=tstate@entry=0x5555568ab628 <_PyRuntime+360584>, frame=frame@entry=0x7e8ff65e5220, throwflag=throwflag@entry=0)
    at ./Include/internal/pycore_ceval.h:118
#18 0x0000555555cb7f0b in _PyEval_Vector (tstate=tstate@entry=0x5555568ab628 <_PyRuntime+360584>, func=func@entry=0x7cfff661ca60, locals=locals@entry=0x7c7ff66885c0, args=args@entry=0x0,
    argcount=argcount@entry=0, kwnames=kwnames@entry=0x0) at Python/ceval.c:2132
#19 0x0000555555cb81bb in PyEval_EvalCode (co=co@entry=0x7d0ff663c0d0, globals=globals@entry=0x7c7ff66885c0, locals=locals@entry=0x7c7ff66885c0) at Python/ceval.c:680
#20 0x0000555555f761b0 in run_eval_code_obj (tstate=tstate@entry=0x5555568ab628 <_PyRuntime+360584>, co=co@entry=0x7d0ff663c0d0, globals=globals@entry=0x7c7ff66885c0,
    locals=locals@entry=0x7c7ff66885c0) at Python/pythonrun.c:1366
#21 0x0000555555f764f6 in run_mod (mod=mod@entry=0x7e4ff65f9b10, filename=filename@entry=0x7c6ff66e4680, globals=globals@entry=0x7c7ff66885c0, locals=locals@entry=0x7c7ff66885c0,
    flags=flags@entry=0x7bfff521b1c0, arena=arena@entry=0x7c7ff66ae5b0, interactive_src=<optimized out>, generate_new_source=<optimized out>) at Python/pythonrun.c:1469

Found using fusil by @vstinner.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

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

Python 3.15.0a6+ (heads/main:70da972f97e, Feb 20 2026, 20:09:41) [GCC 15.2.0]

Linked PRs

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-importlibtype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions