File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ))
You can’t perform that action at this time.
0 commit comments