diff -r 5fea362b92fc Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py Wed Apr 25 19:45:11 2012 +0200 +++ b/Lib/test/test_zipfile.py Sun Apr 29 16:12:14 2012 +0300 @@ -920,6 +920,22 @@ caught.""" self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1) + zip_with_unsupported_compression = ( + b'PK\x03\x04\n\x03\x00\x00\x124\x02{\x9d@2\xd1' + b'Mx\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00te' + b'stTestPK\x01\x02\x14\x03\n\x03\x00\x00' + b'\x124\x02{\x9d@2\xd1Mx\x04\x00\x00\x00\x04\x00' + b'\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x80\xa4\x81' + b'\x00\x00\x00\x00testPK\x05\x06\x00\x00\x00\x00' + b'\x01\x00\x01\x002\x00\x00\x00&\x00\x00\x00\x00\x00') + + def test_unsupported_compression(self): + """Check that attempting to call open() for an item that compressed + with unsupported compression type raises a RuntimeError.""" + zipdata = self.zip_with_unsupported_compression + with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: + self.assertRaises(RuntimeError, zipf.open, "test", "r") + def test_null_byte_in_filename(self): """Check that a filename containing a null byte is properly terminated.""" diff -r 5fea362b92fc Lib/zipfile.py --- a/Lib/zipfile.py Wed Apr 25 19:45:11 2012 +0200 +++ b/Lib/zipfile.py Sun Apr 29 16:12:14 2012 +0300 @@ -487,6 +487,8 @@ if self._compress_type == ZIP_DEFLATED: self._decompressor = zlib.decompressobj(-15) + elif self._compress_type != ZIP_STORED: + raise RuntimeError("Compression method %d is not supported" % self._compress_type) self._unconsumed = b'' self._readbuffer = b''