Skip to content

Commit 0c73db3

Browse files
authored
Merge pull request #7893 from radarhere/osubfiletype
2 parents ca97370 + 3004c46 commit 0c73db3

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Tests/test_file_libtiff.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
from PIL import Image, ImageFilter, ImageOps, TiffImagePlugin, TiffTags, features
15-
from PIL.TiffImagePlugin import SAMPLEFORMAT, STRIPOFFSETS, SUBIFD
15+
from PIL.TiffImagePlugin import OSUBFILETYPE, SAMPLEFORMAT, STRIPOFFSETS, SUBIFD
1616

1717
from .helper import (
1818
assert_image_equal,
@@ -325,6 +325,12 @@ def check_tags(
325325
)
326326
TiffImagePlugin.WRITE_LIBTIFF = False
327327

328+
def test_osubfiletype(self, tmp_path: Path) -> None:
329+
outfile = str(tmp_path / "temp.tif")
330+
with Image.open("Tests/images/g4_orientation_6.tif") as im:
331+
im.tag_v2[OSUBFILETYPE] = 1
332+
im.save(outfile)
333+
328334
def test_subifd(self, tmp_path: Path) -> None:
329335
outfile = str(tmp_path / "temp.tif")
330336
with Image.open("Tests/images/g4_orientation_6.tif") as im:

src/PIL/TiffImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
# Read TIFF files
7575

7676
# a few tag names, just to make the code below a bit more readable
77+
OSUBFILETYPE = 255
7778
IMAGEWIDTH = 256
7879
IMAGELENGTH = 257
7980
BITSPERSAMPLE = 258
@@ -1784,11 +1785,13 @@ def _save(im, fp, filename):
17841785
types = {}
17851786
# STRIPOFFSETS and STRIPBYTECOUNTS are added by the library
17861787
# based on the data in the strip.
1788+
# OSUBFILETYPE is deprecated.
17871789
# The other tags expect arrays with a certain length (fixed or depending on
17881790
# BITSPERSAMPLE, etc), passing arrays with a different length will result in
17891791
# segfaults. Block these tags until we add extra validation.
17901792
# SUBIFD may also cause a segfault.
17911793
blocklist += [
1794+
OSUBFILETYPE,
17921795
REFERENCEBLACKWHITE,
17931796
STRIPBYTECOUNTS,
17941797
STRIPOFFSETS,

0 commit comments

Comments
 (0)