Skip to content

Commit e47c5e1

Browse files
committed
change unpickling to use import rather than retrieving from sys.modules
1 parent f326714 commit e47c5e1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix C implementation of pickle.loads to use importlib's locking
2+
mechanisms, and thereby avoid using partially-loaded modules.
3+
Patch by Tim Burgess.

Modules/_pickle.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6623,14 +6623,9 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
66236623
}
66246624
}
66256625

6626-
module = PyImport_GetModule(module_name);
6627-
if (module == NULL) {
6628-
if (PyErr_Occurred())
6629-
return NULL;
6630-
module = PyImport_Import(module_name);
6631-
if (module == NULL)
6632-
return NULL;
6633-
}
6626+
module = PyImport_Import(module_name);
6627+
if (module == NULL)
6628+
return NULL;
66346629
global = getattribute(module, global_name, self->proto >= 4);
66356630
Py_DECREF(module);
66366631
return global;

0 commit comments

Comments
 (0)