misc: handle PIL SyntaxError when thumbnailing (#49457)

This commit is contained in:
Frédéric Péters 2020-12-14 17:04:13 +01:00
parent fbadefbba6
commit a8fd8136c6
1 changed files with 7 additions and 1 deletions

View File

@ -656,7 +656,13 @@ def get_thumbnail(filepath, content_type=None):
elif orientation == 8:
image = image.rotate(90, expand=1)
image.thumbnail((500, 300))
try:
image.thumbnail((500, 300))
except SyntaxError:
# PIL can raise syntax error on broken PNG files
# * File "PIL/PngImagePlugin.py", line 119, in read
# * raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
raise IOError
image_thumb_fp = BytesIO()
image.save(image_thumb_fp, "PNG")
except IOError: