Skip to content

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

@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

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy