Make extracting zipfiles more resilient against invalid characters in filenames

The previous check applied to actual files but not directories
This commit is contained in:
Kovid Goyal 2020-10-16 19:36:26 +05:30
parent c14c232b33
commit 72b3993fca
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1155,7 +1155,11 @@ class ZipFile:
if member.filename[-1] == '/':
if not os.path.isdir(targetpath):
os.mkdir(targetpath)
try:
os.mkdir(targetpath)
except Exception: # Added by Kovid
targetpath = os.path.join(base_target, sanitize_file_name(fname))
os.mkdir(targetpath)
self.extract_mapping[member.filename] = targetpath
return targetpath