From b8b3cdc146cdc588b7da1f94ba5ab3a196508659 Mon Sep 17 00:00:00 2001 From: homm Date: Fri, 31 Jul 2015 01:20:51 +0300 Subject: [PATCH] fix truncated images loading --- PIL/ImageFile.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index d892ba584..a3d34652f 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -33,7 +33,7 @@ import io import logging import os import sys -# import traceback +import struct logger = logging.getLogger(__name__) @@ -101,7 +101,8 @@ class ImageFile(Image.Image): except (IndexError, # end of data TypeError, # end of data (ord) KeyError, # unsupported mode - EOFError) as v: # got header but not the first frame + EOFError, # got header but not the first frame + struct.error) as v: logger.exception("%s") raise SyntaxError(v) @@ -204,7 +205,7 @@ class ImageFile(Image.Image): while True: try: s = read(self.decodermaxblock) - except IndexError as ie: # truncated png/gif + except (IndexError, struct.error) as ie: # truncated png/gif if LOAD_TRUNCATED_IMAGES: break else: