[3.10] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291) (GH-93140)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 202ed2506c)


Co-authored-by: Sam Ezeh <sam.z.ezeh@gmail.com>

Automerge-Triggered-By: GH:serhiy-storchaka
This commit is contained in:
Miss Islington (bot) 2022-05-25 00:57:56 -07:00 committed by GitHub
parent 2d5d01f26b
commit 132ea29936
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View file

@ -1349,6 +1349,8 @@ class ZipFile:
print("given, inferred, offset", offset_cd, inferred, concat)
# self.start_dir: Position of start of central directory
self.start_dir = offset_cd + concat
if self.start_dir < 0:
raise BadZipFile("Bad offset for central directory")
fp.seek(self.start_dir, 0)
data = fp.read(size_cd)
fp = io.BytesIO(data)