Skip to content

Commit 5370ad1

Browse files
[3.13] gh-126862: Use Py_ssize_t instead of int when processing the number of super-classes (GH-127523) (#128699)
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 <[email protected]>
1 parent 0d2b9ab commit 5370ad1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name,
26492649
*/
26502650

26512651
static int
2652-
tail_contains(PyObject *tuple, int whence, PyObject *o)
2652+
tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o)
26532653
{
26542654
Py_ssize_t j, size;
26552655
size = PyTuple_GET_SIZE(tuple);
@@ -2712,7 +2712,7 @@ check_duplicates(PyObject *tuple)
27122712
*/
27132713

27142714
static void
2715-
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
2715+
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain)
27162716
{
27172717
Py_ssize_t i, n, off;
27182718
char buf[1000];
@@ -2767,13 +2767,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
27672767
{
27682768
int res = 0;
27692769
Py_ssize_t i, j, empty_cnt;
2770-
int *remain;
2770+
Py_ssize_t *remain;
27712771

27722772
/* remain stores an index into each sublist of to_merge.
27732773
remain[i] is the index of the next base in to_merge[i]
27742774
that is not included in acc.
27752775
*/
2776-
remain = PyMem_New(int, to_merge_size);
2776+
remain = PyMem_New(Py_ssize_t, to_merge_size);
27772777
if (remain == NULL) {
27782778
PyErr_NoMemory();
27792779
return -1;

0 commit comments

Comments
 (0)