Skip to content

Commit da13358

Browse files
authored
Merge pull request #7883 from radarhere/tiff
Raise ValueError if seeking to greater than offset-sized integer in TIFF
2 parents 1d733f4 + 21801f3 commit da13358

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Tests/images/seek_too_large.tif

16 Bytes
Binary file not shown.

Tests/test_file_tiff.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ def test_bigtiff(self, tmp_path: Path) -> None:
113113
outfile = str(tmp_path / "temp.tif")
114114
im.save(outfile, save_all=True, append_images=[im], tiffinfo=im.tag_v2)
115115

116+
def test_seek_too_large(self):
117+
with pytest.raises(ValueError, match="Unable to seek to frame"):
118+
Image.open("Tests/images/seek_too_large.tif")
119+
116120
def test_set_legacy_api(self) -> None:
117121
ifd = TiffImagePlugin.ImageFileDirectory_v2()
118122
with pytest.raises(Exception) as e:

src/PIL/TiffImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ def _seek(self, frame):
11671167
self.__next,
11681168
self.fp.tell(),
11691169
)
1170+
if self.__next >= 2**63:
1171+
msg = "Unable to seek to frame"
1172+
raise ValueError(msg)
11701173
self.fp.seek(self.__next)
11711174
self._frame_pos.append(self.__next)
11721175
logger.debug("Loading tags, location: %s", self.fp.tell())

0 commit comments

Comments
 (0)