mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 21:24:46 +03:00
Don't raise IndexError when GPS IFD tag is missing
When images are missing this tag (this is apparently common for many images generated by phones), running them through `ImageOps.exif_transpose` raises `IndexError`. The root cause here is they're missing some tags in the EXIF metadata, and this isn't handled very gracefully. Fixes #4215
This commit is contained in:
parent
398a591e7e
commit
21c7ac8d6a
BIN
Tests/images/exif-gps-ifd-missing.jpeg
Normal file
BIN
Tests/images/exif-gps-ifd-missing.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -735,6 +735,14 @@ class TestFileJpeg:
|
||||||
# Assert the entire file has not been read
|
# Assert the entire file has not been read
|
||||||
assert 0 < buffer.max_pos < size
|
assert 0 < buffer.max_pos < size
|
||||||
|
|
||||||
|
def test_missing_gps_ifd(self):
|
||||||
|
# This image is missing its gps ifd data.
|
||||||
|
with Image.open("Tests/images/exif-gps-ifd-missing.jpeg") as im:
|
||||||
|
|
||||||
|
# This should return the default, and not a IndexError when a tag is
|
||||||
|
# missing.
|
||||||
|
assert im.info.get("dpi") == (72, 72)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||||
@skip_unless_feature("jpg")
|
@skip_unless_feature("jpg")
|
||||||
|
|
|
@ -587,15 +587,20 @@ class ImageFileDirectory_v2(MutableMapping):
|
||||||
TiffTags.SIGNED_RATIONAL,
|
TiffTags.SIGNED_RATIONAL,
|
||||||
]: # rationals
|
]: # rationals
|
||||||
values = (values,)
|
values = (values,)
|
||||||
try:
|
|
||||||
|
if len(values) == 1:
|
||||||
(dest[tag],) = values
|
(dest[tag],) = values
|
||||||
except ValueError:
|
elif len(values) > 1:
|
||||||
# We've got a builtin tag with 1 expected entry
|
# We've got a builtin tag with 1 expected entry
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Metadata Warning, tag %s had too many entries: %s, expected 1"
|
"Metadata Warning, tag %s had too many entries: %s, expected 1"
|
||||||
% (tag, len(values))
|
% (tag, len(values))
|
||||||
)
|
)
|
||||||
dest[tag] = values[0]
|
dest[tag] = values[0]
|
||||||
|
else:
|
||||||
|
warnings.warn(
|
||||||
|
"Metadata Warning, tag %s had no entries, expected 1" % tag
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Spec'd length > 1 or undefined
|
# Spec'd length > 1 or undefined
|
||||||
|
|
Loading…
Reference in New Issue
Block a user