Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,18 @@ def test_too_many_entries() -> None:
assert ifd[277] == 4


def test_tag_offset() -> None:
ifd = TiffImagePlugin.ImageFileDirectory_v2(b"II\x2b\x00" + b"\x00" * 12)

tag_count = struct.pack("Q", 1)
tag = struct.pack("<HHQQ", 0, 1, 9, 2**63)
next_offset = struct.pack("Q", 0)

f = io.BytesIO(tag_count + tag + next_offset)
with pytest.warns(UserWarning, match="Tag offset too large"):
ifd.load(f)


def test_tag_group_data() -> None:
base_ifd = TiffImagePlugin.ImageFileDirectory_v2()
interop_ifd = TiffImagePlugin.ImageFileDirectory_v2(group=40965)
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,9 @@ def load(self, fp: IO[bytes]) -> None:
here = fp.tell()
(offset,) = self._unpack("Q" if self._bigtiff else "L", data)
msg += f" Tag Location: {here} - Data Location: {offset}"
if offset >= 2**63:
warnings.warn("Tag offset too large")
continue
fp.seek(offset)
data = ImageFile._safe_read(fp, size)
fp.seek(here)
Expand Down
Loading