summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorFC Stegerman <flx@obfusk.net>2022-10-29 05:45:46 (GMT)
committerGitHub <noreply@github.com>2022-10-29 05:45:46 (GMT)
commit7ea10567afe38e7770e82b4642c0b01659acaad5 (patch)
tree47d8a66afea23454671851db02732da73258d339 /Lib/zipfile.py
parent0023f51debeeeef483a6362ee12d67c4da086af3 (diff)
downloadcpython-7ea10567afe38e7770e82b4642c0b01659acaad5.zip
cpython-7ea10567afe38e7770e82b4642c0b01659acaad5.tar.gz
cpython-7ea10567afe38e7770e82b4642c0b01659acaad5.tar.bz2
gh-98286: handle empty filename in ZipFile/ZipInfo properly (#98346)
effectively code modernization and a meaningful exception.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index b646537..77b643c 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -553,7 +553,7 @@ class ZipInfo (object):
def is_dir(self):
"""Return True if this archive member is a directory."""
- return self.filename[-1] == '/'
+ return self.filename.endswith('/')
# ZIP encryption uses the CRC32 one-byte primitive for scrambling some
@@ -1731,6 +1731,9 @@ class ZipFile:
# filter illegal characters on Windows
arcname = self._sanitize_windows_name(arcname, os.path.sep)
+ if not arcname:
+ raise ValueError("Empty filename.")
+
targetpath = os.path.join(targetpath, arcname)
targetpath = os.path.normpath(targetpath)
@@ -1820,7 +1823,7 @@ class ZipFile:
date_time=time.localtime(time.time())[:6])
zinfo.compress_type = self.compression
zinfo._compresslevel = self.compresslevel
- if zinfo.filename[-1] == '/':
+ if zinfo.filename.endswith('/'):
zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
zinfo.external_attr |= 0x10 # MS-DOS directory flag
else: