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)
self.log('Rescaling image from %dx%d to %dx%d'%(
width, height, new_width, new_height), item.href)
try:
img = img.resize((new_width, new_height))
except Exception:
self.log.exception('Failed to rescale image: %s' % item.href)
continue
buf = BytesIO()
try:
img.save(buf, ext)
except Exception:
self.log.exception('Failed to rescale image')
self.log.exception('Failed to rescale image: %s' % item.href)
else:
item.data = buf.getvalue()
item.unload_data_from_memory()