mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-31781: Prevent crashes when calling methods of an uninitialized zipimport.zipimporter object (GH-3986)
This commit is contained in:
parent
56cb465cc9
commit
db60a5bfa5
3 changed files with 34 additions and 0 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue