diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-03-22 18:08:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 18:08:00 (GMT) |
commit | 567ab3bd15398c8c7b791f3e376ae3e3c0bbe079 (patch) | |
tree | f65f5fe42810c1159bb48dfe1516daba5e686cb9 /Lib/zipfile | |
parent | 5a78f6e798d5c2af1dba2df6c9f1f1e5aac02a86 (diff) | |
download | cpython-567ab3bd15398c8c7b791f3e376ae3e3c0bbe079.zip cpython-567ab3bd15398c8c7b791f3e376ae3e3c0bbe079.tar.gz cpython-567ab3bd15398c8c7b791f3e376ae3e3c0bbe079.tar.bz2 |
gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129)
Diffstat (limited to 'Lib/zipfile')
-rw-r--r-- | Lib/zipfile/__init__.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index cc08f60..b330ece 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -605,7 +605,15 @@ class ZipInfo: def is_dir(self): """Return True if this archive member is a directory.""" - return self.filename.endswith('/') + 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 |