Skip to content

Commit 2fcdc84

Browse files
authored
gh-126862: Use Py_ssize_t instead of int when processing the number of super-classes (#127523)
1 parent c141748 commit 2fcdc84

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
@@ -2860,7 +2860,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name,
28602860
*/
28612861

28622862
static int
2863-
tail_contains(PyObject *tuple, int whence, PyObject *o)
2863+
tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o)
28642864
{
28652865
Py_ssize_t j, size;
28662866
size = PyTuple_GET_SIZE(tuple);
@@ -2923,7 +2923,7 @@ check_duplicates(PyObject *tuple)
29232923
*/
29242924

29252925
static void
2926-
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
2926+
set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain)
29272927
{
29282928
Py_ssize_t i, n, off;
29292929
char buf[1000];
@@ -2978,13 +2978,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
29782978
{
29792979
int res = 0;
29802980
Py_ssize_t i, j, empty_cnt;
2981-
int *remain;
2981+
Py_ssize_t *remain;
29822982

29832983
/* remain stores an index into each sublist of to_merge.
29842984
remain[i] is the index of the next base in to_merge[i]
29852985
that is not included in acc.
29862986
*/
2987-
remain = PyMem_New(int, to_merge_size);
2987+
remain = PyMem_New(Py_ssize_t, to_merge_size);
29882988
if (remain == NULL) {
29892989
PyErr_NoMemory();
29902990
return -1;

0 commit comments

Comments
 (0)