Skip to content

Commit 1d3d02e

Browse files
committed
Initial commit
1 parent 517d3d2 commit 1d3d02e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Modules/_threadmodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Interface to Sjoerd's portable C thread library */
33

44
#include "Python.h"
5+
//#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION(), Py_END_CRITICAL_SECTION()
56
#include "pycore_fileutils.h" // _PyFile_Flush
67
#include "pycore_interp.h" // _PyInterpreterState.threads.count
78
#include "pycore_lock.h"
@@ -385,6 +386,21 @@ thread_run(void *boot_raw)
385386
PyEval_AcquireThread(tstate);
386387
_Py_atomic_add_ssize(&tstate->interp->threads.count, 1);
387388

389+
#ifdef Py_GIL_DISABLED
390+
// See gh-149816 - (62) Concurrent kwargs growth causes heap overwrite
391+
// So duplicate boot->kwargs to ensure that it won't be mutated concurrently
392+
// by the caller.
393+
if (boot->kwargs != NULL) {
394+
PyObject *n_kwargs = PyDict_Copy(boot->kwargs);
395+
if (n_kwargs == NULL) {
396+
thread_bootstate_free(boot, 1);
397+
goto exit;
398+
}
399+
Py_DECREF(boot->kwargs); // I am not pretty sure about this.
400+
boot->kwargs = n_kwargs;
401+
}
402+
#endif /* Py_GIL_DISABLED */
403+
388404
PyObject *res = PyObject_Call(boot->func, boot->args, boot->kwargs);
389405
if (res == NULL) {
390406
if (PyErr_ExceptionMatches(PyExc_SystemExit))

0 commit comments

Comments
 (0)