From 398b1174b1b9d510d9183c8d29e9fb608a28b6dd Mon Sep 17 00:00:00 2001 From: Kenny Ostrom Date: Thu, 21 Aug 2014 15:58:01 -0500 Subject: [PATCH] fix crash by checking len(v) before accessing v[0] --- PIL/TiffImagePlugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index d5362dee8..8e283e028 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1122,14 +1122,16 @@ def _save(im, fp, filename): # save(load('')) == original file. for k, v in itertools.chain(ifd.items(), getattr(im, 'ifd', {}).items()): + # all adobe defined tags are < 1024 if k not in atts and k not in blocklist and k < 1024: - if type(v[0]) == tuple and len(v) > 1: + # check len(v) before accessing elements + if len(v) > 1 and type(v[0]) == tuple: # A tuple of more than one rational tuples # flatten to floats, # following tiffcp.c->cpTag->TIFF_RATIONAL atts[k] = [float(elt[0])/float(elt[1]) for elt in v] continue - if type(v[0]) == tuple and len(v) == 1: + if len(v) == 1 and type(v[0]) == tuple: # A tuple of one rational tuples # flatten to floats, # following tiffcp.c->cpTag->TIFF_RATIONAL