Skip to content
New issue

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

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

Already on GitHub? # to your account

Added ImageSourceData to TAGS_V2 #7053

Merged
merged 2 commits into from
Apr 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +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_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:
Expand Down
10 changes: 9 additions & 1 deletion docs/releasenotes/9.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============

Expand Down
1 change: 1 addition & 0 deletions src/PIL/TiffTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down