Skip to content

Assertion failure calling _interpreters.run_string with a string subclass instance #132171

Closed
@devdanzin

Description

@devdanzin

Crash report

What happened?

It's possible to make the interpreter abort by calling _interpreters.run_string with an instance of a subclass of str as the script argument:

import _interpreters

class weird_str(str): pass
    
_interpreters.create()
_interpreters.run_string(1, weird_str('1'))
python: ./Modules/_interpretersmodule.c:333: get_code_str: Assertion `PyUnicode_CheckExact(arg) && (check_code_str((PyUnicodeObject *)arg) == NULL)' failed.
Aborted (core dumped)

This happens because, after a check that arg is a str or subclass, there's an assertion that arg is exactly an instance of str:

    if (PyUnicode_Check(arg)) {
        assert(PyUnicode_CheckExact(arg)
               && (check_code_str((PyUnicodeObject *)arg) == NULL));

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.14.0a6+ (heads/main:04bc681e7cf, Apr 4 2025, 12:38:19) [GCC 11.4.0]

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions