summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2019-09-12 14:13:44 (GMT)
committerGregory P. Smith <greg@krypto.org>2019-09-12 14:13:44 (GMT)
commit2f1b857562b0f1601c9019db74c29b7d7e21ac9f (patch)
tree09ba434a35ab308f400440d36aa5a1051d3785bb
parent99b54d68172ad64ba3d0fdc0137f0df88c28ea2b (diff)
downloadcpython-2f1b857562b0f1601c9019db74c29b7d7e21ac9f.zip
cpython-2f1b857562b0f1601c9019db74c29b7d7e21ac9f.tar.gz
cpython-2f1b857562b0f1601c9019db74c29b7d7e21ac9f.tar.bz2
bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
-rw-r--r--Lib/test/test_zipfile.py11
-rw-r--r--Lib/zipfile.py1
-rw-r--r--Misc/NEWS.d/next/Library/2019-09-12-14-52-38.bpo-36991.1OcSm8.rst2
3 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 99d599e..f812188 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
@@ -1766,6 +1767,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 c2c5b6a..97a5ebf 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 0000000..c6fa852
--- /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.