Skip to content

Commit

Permalink
Merge branch 'main' into pycfunctionobject_freelist
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt authored Jan 10, 2025
2 parents e86ccad + 2fcdc84 commit a76224b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,10 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return NULL;
}

// gh-128691: Use deferred reference counting for thread-locals to avoid
// contention on the shared object.
_PyObject_SetDeferredRefcount((PyObject *)self);

self->args = Py_XNewRef(args);
self->kw = Py_XNewRef(kw);

Expand Down
8 changes: 4 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a76224b

Please sign in to comment.