Conversion: Handle corrupted JPEG files that have valid headers but invalid data. Fixes #1622416 [Private bug](https://bugs.launchpad.net/calibre/+bug/1622416)

This commit is contained in:
Kovid Goyal 2016-09-13 08:57:04 +05:30
parent b13b1ea5aa
commit b0f808f2a0

View File

@ -65,12 +65,16 @@ class RescaleImages(object):
new_height = max(1, new_height) new_height = max(1, new_height)
self.log('Rescaling image from %dx%d to %dx%d'%( self.log('Rescaling image from %dx%d to %dx%d'%(
width, height, new_width, new_height), item.href) width, height, new_width, new_height), item.href)
img = img.resize((new_width, new_height)) try:
img = img.resize((new_width, new_height))
except Exception:
self.log.exception('Failed to rescale image: %s' % item.href)
continue
buf = BytesIO() buf = BytesIO()
try: try:
img.save(buf, ext) img.save(buf, ext)
except Exception: except Exception:
self.log.exception('Failed to rescale image') self.log.exception('Failed to rescale image: %s' % item.href)
else: else:
item.data = buf.getvalue() item.data = buf.getvalue()
item.unload_data_from_memory() item.unload_data_from_memory()