Skip to content

gh-98286: handle empty filename in ZipFile/ZipInfo properly #98346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2022

Conversation

obfusk
Copy link
Contributor

@obfusk obfusk commented Oct 17, 2022

@obfusk
Copy link
Contributor Author

obfusk commented Oct 17, 2022

NB: this also raises the ValueError for file names consisting entirely of slashes (which are considered directories, even if they actually contain data), which seems correct to me, but (unlike getting rid of the IndexErrors) could potentially break some existing code (though all tests are green).

>>> import zipfile
>>> fh = zipfile.ZipFile("x.zip")
>>> fh.infolist()
[<ZipInfo filename='///' filemode='drwxrwxr-x' external_attr=0x10>]
>>> fh.extract("///", "some_dir")
ValueError: Empty filename.

@obfusk
Copy link
Contributor Author

obfusk commented Oct 17, 2022

Note that unzip fails to extract file names consisting entirely of slashes as well though:

$ unzip x.zip
Archive:  x.zip
warning:  stripped absolute path spec from ///
mapname:  conversion of  failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants