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

Block TIFFTAG_SUBIFD #5120

Merged
merged 1 commit into from Dec 22, 2020
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
10 changes: 9 additions & 1 deletion Tests/test_file_tiff.py
Expand Up @@ -4,7 +4,7 @@
import pytest

from PIL import Image, TiffImagePlugin
from PIL.TiffImagePlugin import RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION
from PIL.TiffImagePlugin import RESOLUTION_UNIT, SUBIFD, X_RESOLUTION, Y_RESOLUTION

from .helper import (
assert_image_equal,
Expand Down Expand Up @@ -161,6 +161,14 @@ def test_save_dpi_rounding(self, tmp_path):
reloaded.load()
assert (round(dpi), round(dpi)) == reloaded.info["dpi"]

def test_subifd(self, tmp_path):
outfile = str(tmp_path / "temp.tif")
with Image.open("Tests/images/g4_orientation_6.tif") as im:
im.tag_v2[SUBIFD] = 10000

# Should not segfault
im.save(outfile)

def test_save_setting_missing_resolution(self):
b = BytesIO()
Image.open("Tests/images/10ct_32bit_128.tiff").save(
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/TiffImagePlugin.py
Expand Up @@ -89,6 +89,7 @@
PREDICTOR = 317
COLORMAP = 320
TILEOFFSETS = 324
SUBIFD = 330
EXTRASAMPLES = 338
SAMPLEFORMAT = 339
JPEGTABLES = 347
Expand Down Expand Up @@ -1559,12 +1560,14 @@ def _save(im, fp, filename):
# The other tags expect arrays with a certain length (fixed or depending on
# BITSPERSAMPLE, etc), passing arrays with a different length will result in
# segfaults. Block these tags until we add extra validation.
# SUBIFD may also cause a segfault.
blocklist = [
REFERENCEBLACKWHITE,
SAMPLEFORMAT,
STRIPBYTECOUNTS,
STRIPOFFSETS,
TRANSFERFUNCTION,
SUBIFD,
]

atts = {}
Expand Down