From a0671a64d47b3b9a5f4e2fc420090b3c945fc0c9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Feb 2010 15:15:03 -0700 Subject: [PATCH] UNzipping zip files: Workaround invalid zip files that contain end-of-file comments but set comment size to zero. Baen seems to be particularly fond of generating these --- src/calibre/utils/zipfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index 56e96ee8eb..508d9fd319 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -222,7 +222,8 @@ def _EndRecData(fpin): endrec = list(struct.unpack(structEndArchive, recData)) comment = data[start+sizeEndCentDir:] # check that comment length is correct - if endrec[_ECD_COMMENT_SIZE] == len(comment): + # Kovid: Added == 0 check as some zip files apparently dont set this + if endrec[_ECD_COMMENT_SIZE] == 0 or endrec[_ECD_COMMENT_SIZE] == len(comment): # Append the archive comment and start offset endrec.append(comment) endrec.append(maxCommentStart + start)