mirror of
https://github.com/python/cpython.git
synced 2026-06-27 19:36:07 +00:00
[3.15] gh-150633: Properly handle null characters in the name when importing frozen modules (GH-150634) (GH-151100)
(cherry picked from commit 54de5475cd)
Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
This commit is contained in:
parent
e795bd4be7
commit
5751633fac
3 changed files with 13 additions and 1 deletions
|
|
@ -364,6 +364,15 @@ def test_import_raises_ModuleNotFoundError(self):
|
|||
with self.assertRaises(ModuleNotFoundError):
|
||||
import something_that_should_not_exist_anywhere
|
||||
|
||||
def test_import_null_byte_in_name_raises_ModuleNotFoundError(self):
|
||||
# gh-150633: module names containing null bytes should not
|
||||
# lead to duplicates in sys.modules
|
||||
before = set(sys.modules.keys())
|
||||
with self.assertRaises(ModuleNotFoundError):
|
||||
__import__('zipimport\x00junk')
|
||||
|
||||
self.assertEqual(set(sys.modules.keys()), before)
|
||||
|
||||
def test_from_import_missing_module_raises_ModuleNotFoundError(self):
|
||||
with self.assertRaises(ModuleNotFoundError):
|
||||
from something_that_should_not_exist_anywhere import blah
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Fix the frozen importer accepting module names with embedded null bytes, which
|
||||
caused it to bypass the :data:`sys.modules` cache and create duplicate module
|
||||
objects.
|
||||
|
|
@ -3168,7 +3168,7 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
|
|||
if (nameobj == NULL || nameobj == Py_None) {
|
||||
return FROZEN_BAD_NAME;
|
||||
}
|
||||
const char *name = PyUnicode_AsUTF8(nameobj);
|
||||
const char *name = _PyUnicode_AsUTF8NoNUL(nameobj);
|
||||
if (name == NULL) {
|
||||
// Note that this function previously used
|
||||
// _PyUnicode_EqualToASCIIString(). We clear the error here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue