fix truncated images loading

This commit is contained in:
homm 2015-07-31 01:20:51 +03:00
parent 8c3f66a9ae
commit b8b3cdc146

View File

@ -33,7 +33,7 @@ import io
import logging import logging
import os import os
import sys import sys
# import traceback import struct
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -101,7 +101,8 @@ class ImageFile(Image.Image):
except (IndexError, # end of data except (IndexError, # end of data
TypeError, # end of data (ord) TypeError, # end of data (ord)
KeyError, # unsupported mode 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") logger.exception("%s")
raise SyntaxError(v) raise SyntaxError(v)
@ -204,7 +205,7 @@ class ImageFile(Image.Image):
while True: while True:
try: try:
s = read(self.decodermaxblock) s = read(self.decodermaxblock)
except IndexError as ie: # truncated png/gif except (IndexError, struct.error) as ie: # truncated png/gif
if LOAD_TRUNCATED_IMAGES: if LOAD_TRUNCATED_IMAGES:
break break
else: else: