Skip to content

Commit d8965b4

Browse files
committed
add test case
1 parent c405f29 commit d8965b4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/test_importlib/import_/test_relative_imports.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ def test_relative_import_no_package_exists_absolute(self):
223223
self.__import__('sys', {'__package__': '', '__spec__': None},
224224
level=1)
225225

226+
def test_malicious_relative_import(self):
227+
# testing for gh-134100
228+
import sys
229+
loooong = "".ljust(0x23000, "b")
230+
sys.modules.update({f"a.{loooong}.c": {}})
231+
with self.assertRaisesRegex(KeyError, r"'a\.b+' not in sys\.modules as expected"):
232+
__import__(f"{loooong}.c", {"__package__": "a"}, level=1)
233+
226234

227235
(Frozen_RelativeImports,
228236
Source_RelativeImports

0 commit comments

Comments
 (0)