From 72b3993fca26177865416813c293a74506ea6da6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Oct 2020 19:36:26 +0530 Subject: [PATCH] Make extracting zipfiles more resilient against invalid characters in filenames The previous check applied to actual files but not directories --- src/calibre/utils/zipfile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index b7ed5982da..0435e35646 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -1155,7 +1155,11 @@ class ZipFile: if member.filename[-1] == '/': if not os.path.isdir(targetpath): - os.mkdir(targetpath) + try: + os.mkdir(targetpath) + except Exception: # Added by Kovid + targetpath = os.path.join(base_target, sanitize_file_name(fname)) + os.mkdir(targetpath) self.extract_mapping[member.filename] = targetpath return targetpath