mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-34572: change _pickle unpickling to use import rather than retrieving from sys.modules (GH-9047)
Fix C implementation of pickle.loads to use importlib's locking mechanisms, and thereby avoid using partially-loaded modules.
This commit is contained in:
parent
4a7f44a2ed
commit
4371c0a9c0
3 changed files with 75 additions and 7 deletions
|
@ -6636,13 +6636,13 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self,
|
|||
}
|
||||
}
|
||||
|
||||
module = PyImport_GetModule(module_name);
|
||||
/*
|
||||
* we don't use PyImport_GetModule here, because it can return partially-
|
||||
* initialised modules, which then cause the getattribute to fail.
|
||||
*/
|
||||
module = PyImport_Import(module_name);
|
||||
if (module == NULL) {
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
module = PyImport_Import(module_name);
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
global = getattribute(module, global_name, self->proto >= 4);
|
||||
Py_DECREF(module);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue