summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-10-20 20:42:35 (GMT)
committerBrett Cannon <brettcannon@users.noreply.github.com>2017-10-20 20:42:35 (GMT)
commitdb60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e (patch)
treef5dafae436170814bce65b7e189d66ce8b3f2bf2 /Lib
parent56cb465cc93dcb35aaf7266ca3dbe2dcff1fac5f (diff)
downloadcpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.zip
cpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.tar.gz
cpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.tar.bz2
bpo-31781: Prevent crashes when calling methods of an uninitialized zipimport.zipimporter object (GH-3986)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_zipimport.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 4a934ff..67ca39b 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -668,6 +668,20 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
with self.assertWarns(DeprecationWarning):
zipimport.zipimporter(memoryview(os.fsencode(filename)))
+ @support.cpython_only
+ def testUninitializedZipimporter(self):
+ # The interpreter shouldn't crash in case of calling methods of an
+ # uninitialized zipimport.zipimporter object.
+ zi = zipimport.zipimporter.__new__(zipimport.zipimporter)
+ self.assertRaises(ValueError, zi.find_module, 'foo')
+ self.assertRaises(ValueError, zi.find_loader, 'foo')
+ self.assertRaises(ValueError, zi.load_module, 'foo')
+ self.assertRaises(ValueError, zi.get_filename, 'foo')
+ self.assertRaises(ValueError, zi.is_package, 'foo')
+ self.assertRaises(ValueError, zi.get_data, 'foo')
+ self.assertRaises(ValueError, zi.get_code, 'foo')
+ self.assertRaises(ValueError, zi.get_source, 'foo')
+
@support.requires_zlib
class CompressedZipImportTestCase(UncompressedZipImportTestCase):