Skip to content

Commit 21801f3

Browse files
committed
Raise ValueError if seeking to greater than offset-sized integer
1 parent 794a7d6 commit 21801f3

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

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
@@ -1166,6 +1166,9 @@ def _seek(self, frame):
11661166
self.__next,
11671167
self.fp.tell(),
11681168
)
1169+
if self.__next >= 2**63:
1170+
msg = "Unable to seek to frame"
1171+
raise ValueError(msg)
11691172
self.fp.seek(self.__next)
11701173
self._frame_pos.append(self.__next)
11711174
logger.debug("Loading tags, location: %s", self.fp.tell())

0 commit comments

Comments
 (0)