From: Sam Ezeh Date: Mon, 23 May 2022 17:59:21 +0000 (+0100) Subject: gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file... X-Git-Tag: v3.12.0a1~1451 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=202ed2506c84cd98e9e35621b5b2929ceb717864;p=thirdparty%2FPython%2Fcpython.git gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 848bf4f76d45..f4c11d88c8a0 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1740,6 +1740,17 @@ class OtherTests(unittest.TestCase): fp.write("short file") self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN) + def test_negative_central_directory_offset_raises_BadZipFile(self): + # Zip file containing an empty EOCD record + buffer = bytearray(b'PK\x05\x06' + b'\0'*18) + + # Set the size of the central directory bytes to become 1, + # causing the central directory offset to become negative + for dirsize in 1, 2**32-1: + buffer[12:16] = struct.pack('