Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Dec 29, 2020

Resolves #5157

Updated libtiff to 4.2.0, adding a setting to 'winbuild/tiff.opt' because of https://gitlab.com/libtiff/libtiff/-/commit/58b16f47a82323c05ec81f0a821700beb8c2c5a0 (later simplified).

However, from the first commit here, you can see that a test fails.

Investigating, it is failing specifically because of

tc(TiffImagePlugin.IFDRational(4, 7), TiffTags.RATIONAL, True),

libtiff 4.2.0 added the 'Rational2Double' block in this code (if you're interested, it was part of https://gitlab.com/Su_Laus/libtiff/-/commit/6df997c786928757caea0dd68d26ea5f098f49df) -

tv_size = _TIFFDataSize(fip->field_type);
/*--: Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */
if (fip->field_type == TIFF_RATIONAL || fip->field_type == TIFF_SRATIONAL) {
	tv_size = _TIFFSetGetFieldSize(fip->set_field_type);
}
if (tv_size == 0) {
	status = 0;
	TIFFErrorExt(tif->tif_clientdata, module,
		"%s: Bad field type %d for \"%s\"",
		tif->tif_name, fip->field_type,
		fip->field_name);
	goto end;
}

These lines are returning zero for tv_size - I conclude it is because fip->set_field_type is not properly set from https://gitlab.com/libtiff/libtiff/-/blob/v4.2.0/libtiff/tif_dirinfo.c#L1106-1109 in TIFFMergeFieldInfo.

tp->set_field_type =
	 _TIFFSetGetType(info[i].field_type,
		info[i].field_readcount,
		info[i].field_passcount);

This is because _TIFFSetGetType has a few conditions to match against TIFF_RATIONAL -

if (type == TIFF_ASCII && count == TIFF_VARIABLE && passcount == 0)
...
else if (count == 1 && passcount == 0) {
...
else if (count >= 1 && passcount == 0) {
...
else if (count == TIFF_VARIABLE && passcount == 1) {
...
else if (count == TIFF_VARIABLE2 && passcount == 1) {

but none involve count (readcount in TiffDecode.c) being zero.

int readcount = 0;

So this PR changes that value, and the test now passes.

This also then fixes python-pillow/pillow-wheels#180.

@radarhere radarhere added the TIFF label Dec 29, 2020
@radarhere radarhere changed the title Corrected use of TIFFMergeFieldInfo for libtiff 4.2.0 Updated libtiff to 4.2.0 Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testsuite fails with libtiff 4.2.0

2 participants