From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 25 May 2022 07:57:56 +0000 (-0700) Subject: [3.10] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP... X-Git-Tag: v3.10.5~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=132ea299361e08c77c2b02ff25cf31eb73d3642f;p=thirdparty%2FPython%2Fcpython.git [3.10] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291) (GH-93140) 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 6e06ee6a6004..e557d569a119 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1736,6 +1736,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('