summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorSam Ezeh <sam.z.ezeh@gmail.com>2022-05-23 17:59:21 (GMT)
committerGitHub <noreply@github.com>2022-05-23 17:59:21 (GMT)
commit202ed2506c84cd98e9e35621b5b2929ceb717864 (patch)
tree109cc1dc878a5380086cc782b81fb91cfdc1ce51 /Lib/zipfile.py
parent6a6f823ea7f565722148462a0372aa90085637bc (diff)
downloadcpython-202ed2506c84cd98e9e35621b5b2929ceb717864.zip
cpython-202ed2506c84cd98e9e35621b5b2929ceb717864.tar.gz
cpython-202ed2506c84cd98e9e35621b5b2929ceb717864.tar.bz2
gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 9f44375..fc6ca65 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1381,6 +1381,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)