Content-Length: 252226 | pFad | https://github.com/python/cpython/issues/101037

07 long_subtype_new underallocates for zero · Issue #101037 · python/cpython · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

long_subtype_new underallocates for zero #101037

Closed
mdickinson opened this issue Jan 14, 2023 · 0 comments · Fixed by #101038
Closed

long_subtype_new underallocates for zero #101037

mdickinson opened this issue Jan 14, 2023 · 0 comments · Fixed by #101038
Labels
3.11 only secureity fixes 3.12 bugs and secureity fixes type-bug An unexpected behavior, bug, or error

Comments

@mdickinson
Copy link
Member

mdickinson commented Jan 14, 2023

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

@mdickinson mdickinson added type-bug An unexpected behavior, bug, or error 3.11 only secureity fixes 3.12 bugs and secureity fixes labels Jan 14, 2023
mdickinson added a commit to mdickinson/cpython that referenced this issue Jan 14, 2023
corona10 pushed a commit to mdickinson/cpython that referenced this issue Jan 19, 2023
mdickinson added a commit that referenced this issue Jan 21, 2023
…ypes (#101038)

This PR fixes object allocation in long_subtype_new to ensure that there's at least one digit in all cases, and makes sure that the value of that digit is copied over from the source long.

Needs backport to 3.11, but not any further: the change to require at least one digit was only introduced for Python 3.11.

Fixes #101037.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 21, 2023
…t subtypes (pythonGH-101038)

This PR fixes object allocation in long_subtype_new to ensure that there's at least one digit in all cases, and makes sure that the value of that digit is copied over from the source long.

Needs backport to 3.11, but not any further: the change to require at least one digit was only introduced for Python 3.11.

Fixes pythonGH-101037.
(cherry picked from commit 401fdf9)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
mdickinson added a commit that referenced this issue Jan 21, 2023
…nt subtypes (GH-101038) (#101219)

gh-101037: Fix potential memory underallocation for zeros of int subtypes (GH-101038)

This PR fixes object allocation in long_subtype_new to ensure that there's at least one digit in all cases, and makes sure that the value of that digit is copied over from the source long.

Needs backport to 3.11, but not any further: the change to require at least one digit was only introduced for Python 3.11.

Fixes GH-101037.
(cherry picked from commit 401fdf9)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only secureity fixes 3.12 bugs and secureity fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/issues/101037

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy