diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-06-09 20:01:09 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-06-09 20:01:09 (GMT) |
commit | 873c583244193f15b57293bce579c8410e747e20 (patch) | |
tree | 7b549c06b75c6ec2943c56bb0a270d4baa0ec183 /Lib/zipfile.py | |
parent | 5446f08c608d8e0041c8bb27b74be713db050177 (diff) | |
download | cpython-873c583244193f15b57293bce579c8410e747e20.zip cpython-873c583244193f15b57293bce579c8410e747e20.tar.gz cpython-873c583244193f15b57293bce579c8410e747e20.tar.bz2 |
#10694: zipfile now ignores garbage at the end of a zipfile.
Original fix by 'rep', final patch (with tests) by Xuanji Li.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 7e3caf0..f876f42 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -236,16 +236,14 @@ def _EndRecData(fpin): # found the magic number; attempt to unpack and interpret recData = data[start:start+sizeEndCentDir] endrec = list(struct.unpack(structEndArchive, recData)) - comment = data[start+sizeEndCentDir:] - # check that comment length is correct - if endrec[_ECD_COMMENT_SIZE] == len(comment): - # Append the archive comment and start offset - endrec.append(comment) - endrec.append(maxCommentStart + start) - - # Try to read the "Zip64 end of central directory" structure - return _EndRecData64(fpin, maxCommentStart + start - filesize, - endrec) + commentSize = endrec[_ECD_COMMENT_SIZE] #as claimed by the zip file + comment = data[start+sizeEndCentDir:start+sizeEndCentDir+commentSize] + endrec.append(comment) + endrec.append(maxCommentStart + start) + + # Try to read the "Zip64 end of central directory" structure + return _EndRecData64(fpin, maxCommentStart + start - filesize, + endrec) # Unable to find a valid end of central directory structure return |