SubIFD offsets should only be added if smaller pyramid layers actually exist. Otherwise results in corrupted TIFF files for images smaller than the tile size (#3058)

This commit is contained in:
Ruven 2022-09-22 14:36:27 +02:00 committed by GitHub
parent 1f8e547d99
commit cdf497d3e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2128,11 +2128,14 @@ wtiff_page_start( Wtiff *wtiff )
*/
for( n_layers = 0, p = wtiff->layer->below; p; p = p->below )
n_layers += 1;
subifd_offsets = VIPS_ARRAY( NULL, n_layers, toff_t );
memset( subifd_offsets, 0, n_layers * sizeof( toff_t ) );
TIFFSetField( wtiff->layer->tif, TIFFTAG_SUBIFD,
n_layers, subifd_offsets );
g_free( subifd_offsets );
if( n_layers > 0 ){
subifd_offsets = VIPS_ARRAY( NULL, n_layers, toff_t );
memset( subifd_offsets, 0, n_layers * sizeof( toff_t ) );
TIFFSetField( wtiff->layer->tif, TIFFTAG_SUBIFD,
n_layers, subifd_offsets );
g_free( subifd_offsets );
}
}
return( 0 );