mirror of
https://github.com/python/cpython.git
synced 2026-06-23 17:46:08 +00:00
[3.15] gh-146452: Fix pickle segfault on concurrent mutation of dict in pickle (GH-146470) (#150292)
gh-146452: Fix pickle segfault on concurrent mutation of dict in pickle (GH-146470)
(cherry picked from commit e62a61177f)
Co-authored-by: Farhan Saif <fsaif@uic.edu>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
795dd3bd35
commit
77cc4428a7
3 changed files with 59 additions and 1 deletions
|
|
@ -3452,7 +3452,7 @@ batch_dict(PickleState *state, PicklerObject *self, PyObject *iter, PyObject *or
|
|||
* Note that this currently doesn't work for protocol 0.
|
||||
*/
|
||||
static int
|
||||
batch_dict_exact(PickleState *state, PicklerObject *self, PyObject *obj)
|
||||
batch_dict_exact_impl(PickleState *state, PicklerObject *self, PyObject *obj)
|
||||
{
|
||||
PyObject *key = NULL, *value = NULL;
|
||||
int i;
|
||||
|
|
@ -3525,6 +3525,18 @@ batch_dict_exact(PickleState *state, PicklerObject *self, PyObject *obj)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* gh-146452: Wrap the dict iteration in a critical section to prevent
|
||||
concurrent mutation from invalidating PyDict_Next() iteration state. */
|
||||
static int
|
||||
batch_dict_exact(PickleState *state, PicklerObject *self, PyObject *obj)
|
||||
{
|
||||
int ret;
|
||||
Py_BEGIN_CRITICAL_SECTION(obj);
|
||||
ret = batch_dict_exact_impl(state, self, obj);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
save_dict(PickleState *state, PicklerObject *self, PyObject *obj)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue