diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-12 07:33:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-12 07:33:53 -0700 |
commit | 717cc61ed103684b8c73e0e8af10ace345f39f16 (patch) | |
tree | 6296a581a2b43c84fc454d70e85f57893f2a3f1b | |
parent | 0d7cb5bb291d8645824581ae570a394e3d221e5e (diff) | |
download | cpython-git-717cc61ed103684b8c73e0e8af10ace345f39f16.tar.gz |
bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
(cherry picked from commit 2f1b857562b0f1601c9019db74c29b7d7e21ac9f)
Co-authored-by: Berker Peksag <berker.peksag@gmail.com>
-rw-r--r-- | Lib/test/test_zipfile.py | 11 | ||||
-rw-r--r-- | Lib/zipfile.py | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-09-12-14-52-38.bpo-36991.1OcSm8.rst | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 955e540f96..76e2f647c6 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -9,6 +9,7 @@ import subprocess import sys import time import unittest +import unittest.mock as mock import zipfile @@ -1739,6 +1740,16 @@ class OtherTests(unittest.TestCase): fp.seek(0, os.SEEK_SET) self.assertEqual(fp.tell(), 0) + @requires_bz2 + def test_decompress_without_3rd_party_library(self): + data = b'PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + zip_file = io.BytesIO(data) + with zipfile.ZipFile(zip_file, 'w', compression=zipfile.ZIP_BZIP2) as zf: + zf.writestr('a.txt', b'a') + with mock.patch('zipfile.bz2', None): + with zipfile.ZipFile(zip_file) as zf: + self.assertRaises(RuntimeError, zf.extract, 'a.txt') + def tearDown(self): unlink(TESTFN) unlink(TESTFN2) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index dfd0907950..59435064ea 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -703,6 +703,7 @@ def _get_compressor(compress_type, compresslevel=None): def _get_decompressor(compress_type): + _check_compression(compress_type) if compress_type == ZIP_STORED: return None elif compress_type == ZIP_DEFLATED: diff --git a/Misc/NEWS.d/next/Library/2019-09-12-14-52-38.bpo-36991.1OcSm8.rst b/Misc/NEWS.d/next/Library/2019-09-12-14-52-38.bpo-36991.1OcSm8.rst new file mode 100644 index 0000000000..c6fa852e94 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-09-12-14-52-38.bpo-36991.1OcSm8.rst @@ -0,0 +1,2 @@ +Fixes a potential incorrect AttributeError exception escaping +ZipFile.extract() in some unsupported input error situations. |