ZIP file extraction: Fix extracting into directory whose path is specified with a UNC path on windows causing file names to get mangled

This commit is contained in:
Kovid Goyal 2017-05-10 23:49:54 +05:30
parent 41aadb096c
commit b92ac5578e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -33,6 +33,7 @@ class LargeZipFile(Exception):
and those extensions are disabled. and those extensions are disabled.
""" """
error = BadZipfile # The exception raised by this module error = BadZipfile # The exception raised by this module
ZIP64_LIMIT = (1 << 31) - 1 ZIP64_LIMIT = (1 << 31) - 1
@ -1122,6 +1123,10 @@ class ZipFile:
raise BadZipfile('The member %r has an invalid name'%member.filename) raise BadZipfile('The member %r has an invalid name'%member.filename)
targetpath = os.path.normpath(os.path.join(base_target, fname)) targetpath = os.path.normpath(os.path.join(base_target, fname))
# Added by Kovid as normpath fails to convert forward slashes for UNC
# paths, i.e. paths of the form \\?\C:\some/path
if os.sep != '/':
targetpath = targetpath.replace('/', os.sep)
# Create all upper directories if necessary. # Create all upper directories if necessary.
upperdirs = os.path.dirname(targetpath) upperdirs = os.path.dirname(targetpath)
@ -1682,5 +1687,6 @@ def main(args=None):
zf.close() zf.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()