From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 25 May 2022 07:57:36 +0000 (-0700) Subject: [3.11] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP... X-Git-Tag: v3.11.0b2~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9d6ca4334273d44e7bd369d119380b4b7d9807d;p=thirdparty%2FPython%2Fcpython.git [3.11] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291) (GH-93141) Co-authored-by: Serhiy Storchaka (cherry picked from commit 202ed2506c84cd98e9e35621b5b2929ceb717864) Co-authored-by: Sam Ezeh Automerge-Triggered-By: GH: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('