From d79b1d4a042095d1c4ad6d54f67239822bdf1c81 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Wed, 14 Dec 2016 07:42:03 -0800 Subject: [PATCH] Warning on count or type mismatch on exif data --- PIL/TiffImagePlugin.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 713878b1e..1a03d59fe 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -666,11 +666,22 @@ class ImageFileDirectory_v2(collections.MutableMapping): try: for i in range(self._unpack("H", self._ensure_read(fp, 2))[0]): tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp, 12)) + taginfo = TiffTags.lookup(tag) if DEBUG: - tagname = TiffTags.lookup(tag).name typname = TYPES.get(typ, "unknown") - print("tag: %s (%d) - type: %s (%d)" % - (tagname, tag, typname, typ), end=" ") + print("tag: %s (%d) - type: %s (%d) - spec type: %s - count: %d, spec ct: %d" % + (taginfo.name, tag, typname, typ, + taginfo.type, count, taginfo.length), end=" ") + + if (taginfo.type and typ != taginfo.type): + warnings.warn(("Possibly corrupt EXIF data. " + + "File tag type %s does not match spec %s for tag %s" + ) % (typ, taginfo.type, tag)) + + if (taginfo.length and count != taginfo.length): + warnings.warn(("Possibly corrupt EXIF data. " + + "File tag count %s does not match spec %s for tag %s" + ) % (count, taginfo.length, tag)) try: unit_size, handler = self._load_dispatch[typ]