mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
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:
parent
41aadb096c
commit
b92ac5578e
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user