EPUB Input: Fix an infinite loop while trying to unzip a damaged EPUB file. Fixes #1086917 (Load never terminates epub file is truncated)

This commit is contained in:
Kovid Goyal 2012-12-06 08:59:34 +05:30
parent 3e48983a9c
commit 7633b69c8d

View File

@ -152,6 +152,8 @@ def copy_compressed_file(src, size, dest):
amt = min(size, 20*1024) amt = min(size, 20*1024)
while read < size: while read < size:
raw = src.read(min(size-read, amt)) raw = src.read(min(size-read, amt))
if not raw and read < size:
raise ValueError('Invalid ZIP file, local header is damaged')
read += len(raw) read += len(raw)
dest.write(d.decompress(raw, 200*1024)) dest.write(d.decompress(raw, 200*1024))
count = 0 count = 0