[3.11] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162) (GH-117165)

(cherry picked from commit f3fee231d3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 567ab3bd15)
This commit is contained in:
Serhiy Storchaka 2024-03-22 21:24:27 +02:00 committed by GitHub
parent da5efeba93
commit 0d82047645
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

View file

@ -559,7 +559,15 @@ class ZipInfo (object):
def is_dir(self):
"""Return True if this archive member is a directory."""
return self.filename[-1] == '/'
if self.filename.endswith('/'):
return True
# The ZIP format specification requires to use forward slashes
# as the directory separator, but in practice some ZIP files
# created on Windows can use backward slashes. For compatibility
# with the extraction code which already handles this:
if os.path.altsep:
return self.filename.endswith((os.path.sep, os.path.altsep))
return False
# ZIP encryption uses the CRC32 one-byte primitive for scrambling some