Skip to content

long_subtype_new underallocates for zero #101037

@mdickinson

Description

@mdickinson

When creating int instances, we always allocate space for and initialise at least one digit, since the medium_value function that's used for fast paths assumes the existence of that digit. This change was introduced for Python 3.11 in PR #27832.

However, the corresponding change in long_subtype_new was missed; this results in us asking for zero digits in the case of creating an instance of a subclass of int with value zero - e.g.,

class MyInt(int):
    pass

myint = MyInt()  # problem

That's then a problem if myint is used in a context where medium_value might be called on it, for example as in int(myint).

We've got away with this so far because of a compensating overallocation issue: see #81381; this bug blocked an attempt to address #81381 in #100855. But I believe this should still be fixed.

I'll make a PR shortly.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    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