mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.11] gh-101037: Fix potential memory underallocation for zeros of int 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 401fdf9c85
)
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
99da75e770
commit
d2aaf818ae
3 changed files with 10 additions and 0 deletions
|
@ -5415,6 +5415,11 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase)
|
|||
n = Py_SIZE(tmp);
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
/* Fast operations for single digit integers (including zero)
|
||||
* assume that there is always at least one digit present. */
|
||||
if (n == 0) {
|
||||
n = 1;
|
||||
}
|
||||
newobj = (PyLongObject *)type->tp_alloc(type, n);
|
||||
if (newobj == NULL) {
|
||||
Py_DECREF(tmp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue