mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-101037: Fix potential memory underallocation for zeros of int subtypes (#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.
This commit is contained in:
parent
9e947675ae
commit
401fdf9c85
3 changed files with 10 additions and 0 deletions
|
|
@ -5638,6 +5638,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