Warning on count or type mismatch on exif data

This commit is contained in:
wiredfool 2016-12-14 07:42:03 -08:00
parent c69500e026
commit d79b1d4a04

View File

@ -666,11 +666,22 @@ class ImageFileDirectory_v2(collections.MutableMapping):
try: try:
for i in range(self._unpack("H", self._ensure_read(fp, 2))[0]): 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)) tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp, 12))
taginfo = TiffTags.lookup(tag)
if DEBUG: if DEBUG:
tagname = TiffTags.lookup(tag).name
typname = TYPES.get(typ, "unknown") typname = TYPES.get(typ, "unknown")
print("tag: %s (%d) - type: %s (%d)" % print("tag: %s (%d) - type: %s (%d) - spec type: %s - count: %d, spec ct: %d" %
(tagname, tag, typname, typ), end=" ") (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: try:
unit_size, handler = self._load_dispatch[typ] unit_size, handler = self._load_dispatch[typ]