Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ValueError if seeking to greater than offset-sized integer in TIFF #7883

Merged
merged 1 commit into from Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/seek_too_large.tif
Binary file not shown.
4 changes: 4 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -113,6 +113,10 @@ def test_bigtiff(self, tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.tif")
im.save(outfile, save_all=True, append_images=[im], tiffinfo=im.tag_v2)

def test_seek_too_large(self):
with pytest.raises(ValueError, match="Unable to seek to frame"):
Image.open("Tests/images/seek_too_large.tif")

def test_set_legacy_api(self) -> None:
ifd = TiffImagePlugin.ImageFileDirectory_v2()
with pytest.raises(Exception) as e:
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/TiffImagePlugin.py
Expand Up @@ -1166,6 +1166,9 @@ def _seek(self, frame):
self.__next,
self.fp.tell(),
)
if self.__next >= 2**63:
msg = "Unable to seek to frame"
raise ValueError(msg)
self.fp.seek(self.__next)
self._frame_pos.append(self.__next)
logger.debug("Loading tags, location: %s", self.fp.tell())
Expand Down