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

This commit is contained in:
Kovid Goyal 2010-02-10 15:15:03 -07:00
parent f587a7e825
commit a0671a64d4

View File

@ -222,7 +222,8 @@ def _EndRecData(fpin):
endrec = list(struct.unpack(structEndArchive, recData)) endrec = list(struct.unpack(structEndArchive, recData))
comment = data[start+sizeEndCentDir:] comment = data[start+sizeEndCentDir:]
# check that comment length is correct # 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 # Append the archive comment and start offset
endrec.append(comment) endrec.append(comment)
endrec.append(maxCommentStart + start) endrec.append(maxCommentStart + start)