From eba87ac6d9e9e515b89140b06f65e66bc3d39191 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Wed, 30 Dec 2015 13:34:33 -0800 Subject: [PATCH] Catch the IFD error near the source --- PIL/JpegImagePlugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 5305fe6e5..12399ac4e 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -453,9 +453,12 @@ def _getmp(self): head = file_contents.read(8) endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<' # process dictionary - info = TiffImagePlugin.ImageFileDirectory_v2(head) - info.load(file_contents) - mp = dict(info) + try: + info = TiffImagePlugin.ImageFileDirectory_v2(head) + info.load(file_contents) + mp = dict(info) + except: + raise SyntaxError("malformed MP Index (unreadable directory)") # it's an error not to have a number of images try: quant = mp[0xB001]