Skip to content

Commit b55c404

Browse files
[3.12] gh-126862: Use Py_ssize_t instead of int when processing the number of super-classes (GH-127523) (#128700)
gh-126862: Use `Py_ssize_t` instead of `int` when processing the number of super-classes (GH-127523) (cherry picked from commit 2fcdc84) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 8bfc68f commit b55c404

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible overflow when a class inherits from an absurd number of
2+
super-classes. Reported by Valery Fedorenko. Patch by Bénédikt Tran.

Objects/typeobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name,
23192319
*/
23202320

23212321
static int
2322-
tail_contains(PyObject *tuple, int whence, PyObject *o)
2322+
tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o)
23232323
{
23242324
Py_ssize_t j, size;
23252325
size = PyTuple_GET_SIZE(tuple);
@@ -2382,7 +2382,7 @@ check_duplicates(PyObject *tuple)
23822382
*/
23832383

23842384
static void
2385-
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
2385+
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain)
23862386
{
23872387
Py_ssize_t i, n, off;
23882388
char buf[1000];
@@ -2437,13 +2437,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
24372437
{
24382438
int res = 0;
24392439
Py_ssize_t i, j, empty_cnt;
2440-
int *remain;
2440+
Py_ssize_t *remain;
24412441

24422442
/* remain stores an index into each sublist of to_merge.
24432443
remain[i] is the index of the next base in to_merge[i]
24442444
that is not included in acc.
24452445
*/
2446-
remain = PyMem_New(int, to_merge_size);
2446+
remain = PyMem_New(Py_ssize_t, to_merge_size);
24472447
if (remain == NULL) {
24482448
PyErr_NoMemory();
24492449
return -1;

0 commit comments

Comments
 (0)