Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
importosfrompathlibimportPathfromzipfileimportZipFiledefunzip(target_file,destination=Path("/tmp/")):os.path.altsep="\\"withZipFile(target_file,"r")aszipf:zipf.extractall(path=destination)
Im building a small web service which allows user to upload zip files containing docshttps://github.com/docat-org/docat/blob/main/docat/docat/utils.py#L36 which get unpackt and hosted.
Because of that people create zip files on windows which we try to unpack on linux.
Which fails:
Traceback (most recent call last): File "/home/user/Downloads/example/test.py", line 71, in <module> unzip(Path("/home/user/Downloads/example/devdocu.zip")) File "/home/user/Downloads/example/test.py", line 66, in unzip zipf.extractall(path=destination) File "/home/user/.asdf/installs/python/3.12.2/lib/python3.12/zipfile/__init__.py", line 1734, in extractall self._extract_member(zipinfo, path, pwd) File "/home/user/.asdf/installs/python/3.12.2/lib/python3.12/zipfile/__init__.py", line 1784, in _extract_member os.makedirs(upperdirs) File "<frozen os>", line 225, in makedirsNotADirectoryError: [Errno 20] Not a directory: '/tmp/DevDocu/articles/XXXX/FBRT/BackupAndRestore'Unfortunately i can't share the actual zip file as it contains sensitive data.
Butzip -T thinks it is ok andunzip unpacks this zip without issues.
A bit of digging showed the problem as far as i can tell is inis_dir which claims that
self.filename='DevDocu\\articles\\XXX\\FBRT\\' is_dir? Falseis a file and creates an empty file instead of a dir.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-117084: Fix zip extraction bug #117085
- gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows #117129
- [3.12] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) #117162
- [3.11] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162) #117165
Metadata
Metadata
Assignees
Projects
Status
Done