Skip to content

Abort when using a tuple subclass instance as the bases parameter for type #132176

Closed

Description

@devdanzin

Crash report

What happened?

The interpreter will abort when a new type is created using an instance of a subclass of tuple as the bases parameter due to a PyTuple_CheckExact(bases) assertion:

class weird_tuple(tuple): pass

c = type("c", weird_tuple((str,)), {})
python: Objects/typeobject.c:500: set_tp_bases: Assertion `PyTuple_CheckExact(bases)' failed.
Aborted (core dumped)

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

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Apr 6, 2025
  2. xuantengh commented on Apr 7, 2025

    @xuantengh
    Contributor

    The doc states the 2nd arg when type() receives 3 arguments should be a tuple. Maybe we should raise an exception if bases cannot pass the PyTuple_CheckExact check?

  3. devdanzin commented on Apr 7, 2025

    @devdanzin
    MemberAuthor

    Maybe we should raise an exception if bases cannot pass the PyTuple_CheckExact check?

    Maybe, but it works in release builds, resulting in a class where __bases__ is the instance of the tuple subclass we passed to type. So there's a chance somebody out there is using this in some way.

  4. xuantengh commented on Apr 7, 2025

    @xuantengh
    Contributor

    Otherwise we should relax the assert with PyTuple_Check.

  5. sobolevn commented on Apr 7, 2025

    @sobolevn
    Member

    I think that it should be an exact tuple for _Py_SetImmortal call and it can be a tuple subclass for regular classes. This problem exists since 3.12

    Thanks for the report! 🤝

  6. self-assigned this
    on Apr 7, 2025
  7. added a commit that references this issue on Apr 7, 2025
  8. added a commit that references this issue on Apr 15, 2025
  9. added a commit that references this issue on Apr 15, 2025
  10. added a commit that references this issue on Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-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