From aa9ecac0328a7dce7d7f3bd3d0ee7a9ec0316f83 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 1 Apr 2023 10:27:39 +1100 Subject: [PATCH 1/2] Added ImageSourceData to TAGS_V2 --- Tests/test_file_libtiff.py | 5 +++++ docs/releasenotes/9.5.0.rst | 10 +++++++++- src/PIL/TiffTags.py | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 7a94c0302f9..53cfd81f702 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -668,6 +668,11 @@ def test_save_ycbcr(self, tmp_path): assert reloaded.tag_v2[530] == (1, 1) assert reloaded.tag_v2[532] == (0, 255, 128, 255, 128, 255) + def test_save_imagesourcedata(self, tmp_path): + outfile = str(tmp_path / "temp.tif") + with Image.open("Tests/images/tiff_adobe_deflate.tif") as im: + im.save(outfile) + def test_crashing_metadata(self, tmp_path): # issue 1597 with Image.open("Tests/images/rdf.tif") as im: diff --git a/docs/releasenotes/9.5.0.rst b/docs/releasenotes/9.5.0.rst index 1ba9b98905b..9157210827c 100644 --- a/docs/releasenotes/9.5.0.rst +++ b/docs/releasenotes/9.5.0.rst @@ -72,10 +72,18 @@ data to populate those resources. PpmImagePlugin might hold onto the last data read for a pixel value in case the pixel value has not been finished yet. However, that data was not being cleared afterwards, meaning that infinite data could be available to fill any image -size. +size. This has been present since Pillow 9.2.0. That data is now cleared after use. +Saving TIFF tag ImageSourceData +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +If Pillow incorrectly saved the TIFF tag ImageSourceData as ASCII instead of +UNDEFINED, a segmentation fault was triggered. + +The correct tag type will now be used by default instead. + Other Changes ============= diff --git a/src/PIL/TiffTags.py b/src/PIL/TiffTags.py index ac048ba562f..30b05e4e1d4 100644 --- a/src/PIL/TiffTags.py +++ b/src/PIL/TiffTags.py @@ -195,6 +195,7 @@ def lookup(tag, group=None): 34675: ("ICCProfile", UNDEFINED, 1), 34853: ("GPSInfoIFD", LONG, 1), 36864: ("ExifVersion", UNDEFINED, 1), + 37724: ("ImageSourceData", UNDEFINED, 1), 40965: ("InteroperabilityIFD", LONG, 1), 41730: ("CFAPattern", UNDEFINED, 1), # MPInfo From b1b0353d17bcdca99cfcb2ea48c6af7861fb43ba Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 1 Apr 2023 12:21:16 +1100 Subject: [PATCH 2/2] Corrected passing TIFF_LONG to libtiff --- Tests/test_file_libtiff.py | 7 ++++++- src/encode.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 53cfd81f702..ac78b086965 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -668,11 +668,16 @@ def test_save_ycbcr(self, tmp_path): assert reloaded.tag_v2[530] == (1, 1) assert reloaded.tag_v2[532] == (0, 255, 128, 255, 128, 255) - def test_save_imagesourcedata(self, tmp_path): + def test_exif_ifd(self, tmp_path): outfile = str(tmp_path / "temp.tif") with Image.open("Tests/images/tiff_adobe_deflate.tif") as im: + assert im.tag_v2[34665] == 125456 im.save(outfile) + with Image.open(outfile) as reloaded: + if Image.core.libtiff_support_custom_tags: + assert reloaded.tag_v2[34665] == 125456 + def test_crashing_metadata(self, tmp_path): # issue 1597 with Image.open("Tests/images/rdf.tif") as im: diff --git a/src/encode.c b/src/encode.c index a665949357f..308bd2059cc 100644 --- a/src/encode.c +++ b/src/encode.c @@ -904,7 +904,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { &encoder->state, (ttag_t)key_int, (UINT16)PyLong_AsLong(value)); } else if (type == TIFF_LONG) { status = ImagingLibTiffSetField( - &encoder->state, (ttag_t)key_int, (UINT32)PyLong_AsLong(value)); + &encoder->state, (ttag_t)key_int, PyLong_AsLongLong(value)); } else if (type == TIFF_SSHORT) { status = ImagingLibTiffSetField( &encoder->state, (ttag_t)key_int, (INT16)PyLong_AsLong(value));