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 John Cupitt
parent b0be5beb30
commit 33d44e86fb
1 changed files with 8 additions and 5 deletions

View File

@ -2127,11 +2127,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 );