mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix #1045: Recover from decompression errors, skipping bad chunks.
This commit is contained in:
parent
a91fa52351
commit
a18e35cfec
@ -771,15 +771,21 @@ class LitReader(object):
|
|||||||
raise("Reset table entry out of bounds")
|
raise("Reset table entry out of bounds")
|
||||||
if bytes_remaining >= window_bytes:
|
if bytes_remaining >= window_bytes:
|
||||||
lzx.reset()
|
lzx.reset()
|
||||||
result.append(
|
try:
|
||||||
lzx.decompress(content[base:size], window_bytes))
|
result.append(
|
||||||
|
lzx.decompress(content[base:size], window_bytes))
|
||||||
|
except lzx.LzxError:
|
||||||
|
self._warn("LZX decompression error; skipping chunk")
|
||||||
bytes_remaining -= window_bytes
|
bytes_remaining -= window_bytes
|
||||||
base = size
|
base = size
|
||||||
accum += int32(reset_table[RESET_INTERVAL:])
|
accum += int32(reset_table[RESET_INTERVAL:])
|
||||||
ofs_entry += 8
|
ofs_entry += 8
|
||||||
if bytes_remaining < window_bytes and bytes_remaining > 0:
|
if bytes_remaining < window_bytes and bytes_remaining > 0:
|
||||||
lzx.reset()
|
lzx.reset()
|
||||||
result.append(lzx.decompress(content[base:], bytes_remaining))
|
try:
|
||||||
|
result.append(lzx.decompress(content[base:], bytes_remaining))
|
||||||
|
except lzx.LzxError:
|
||||||
|
self._warn("LZX decompression error; skipping chunk")
|
||||||
bytes_remaining = 0
|
bytes_remaining = 0
|
||||||
if bytes_remaining > 0:
|
if bytes_remaining > 0:
|
||||||
raise LitError("Failed to completely decompress section")
|
raise LitError("Failed to completely decompress section")
|
||||||
@ -826,6 +832,9 @@ class LitReader(object):
|
|||||||
if not os.path.isdir(dir):
|
if not os.path.isdir(dir):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
|
||||||
|
def _warn(self, msg):
|
||||||
|
print "WARNING: %s" % (msg,)
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
parser = OptionParser(usage=_('%prog [options] LITFILE'))
|
parser = OptionParser(usage=_('%prog [options] LITFILE'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user