summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2025-01-10 03:32:53 (GMT)
committerGitHub <noreply@github.com>2025-01-10 03:32:53 (GMT)
commit2fcdc8488c32d18f4567f797094068a994777f16 (patch)
tree822531c30c64b7809df5a1fbc97a79c29e46e8aa
parentc1417487e98e270d614965ed78ff9439044b65a6 (diff)
downloadcpython-2fcdc8488c32d18f4567f797094068a994777f16.zip
cpython-2fcdc8488c32d18f4567f797094068a994777f16.tar.gz
cpython-2fcdc8488c32d18f4567f797094068a994777f16.tar.bz2
gh-126862: Use `Py_ssize_t` instead of `int` when processing the number of super-classes (#127523)
-rw-r--r--Misc/NEWS.d/next/Core_and_Builtins/2024-12-02-18-15-37.gh-issue-126862.fdIK7T.rst2
-rw-r--r--Objects/typeobject.c8
2 files changed, 6 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-12-02-18-15-37.gh-issue-126862.fdIK7T.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-02-18-15-37.gh-issue-126862.fdIK7T.rst
new file mode 100644
index 0000000..d930c29
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-02-18-15-37.gh-issue-126862.fdIK7T.rst
@@ -0,0 +1,2 @@
+Fix a possible overflow when a class inherits from an absurd number of
+super-classes. Reported by Valery Fedorenko. Patch by Bénédikt Tran.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 7f95b51..680846f 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2860,7 +2860,7 @@ vectorcall_maybe(PyThreadState *tstate, PyObject *name,
*/
static int
-tail_contains(PyObject *tuple, int whence, PyObject *o)
+tail_contains(PyObject *tuple, Py_ssize_t whence, PyObject *o)
{
Py_ssize_t j, size;
size = PyTuple_GET_SIZE(tuple);
@@ -2923,7 +2923,7 @@ check_duplicates(PyObject *tuple)
*/
static void
-set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, int *remain)
+set_mro_error(PyObject **to_merge, Py_ssize_t to_merge_size, Py_ssize_t *remain)
{
Py_ssize_t i, n, off;
char buf[1000];
@@ -2978,13 +2978,13 @@ pmerge(PyObject *acc, PyObject **to_merge, Py_ssize_t to_merge_size)
{
int res = 0;
Py_ssize_t i, j, empty_cnt;
- int *remain;
+ Py_ssize_t *remain;
/* remain stores an index into each sublist of to_merge.
remain[i] is the index of the next base in to_merge[i]
that is not included in acc.
*/
- remain = PyMem_New(int, to_merge_size);
+ remain = PyMem_New(Py_ssize_t, to_merge_size);
if (remain == NULL) {
PyErr_NoMemory();
return -1;