Skip to content

Commit

Permalink
fix out of order read for some tiff
Browse files Browse the repository at this point in the history
Make sure we always have min of two strips in a linecache. Plane
separate tiffs with large rows-per-strip could shrink the cache to a
single block of pixels, which would then fail if the output straddled a
tile boundary.

See #1158

Thanks @chregu for the report.
  • Loading branch information
jcupitt committed Nov 25, 2018
1 parent 2b70333 commit 3887d8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion libvips/conversion/tilecache.c
Expand Up @@ -939,8 +939,14 @@ vips_line_cache_build( VipsObject *object )
/* Output has two buffers n_lines height, so 2 * n_lines is the maximum
* non-locality from threading. Add another n_lines for conv / reducev
* etc.
*
* tile_height can be huge for things like tiff read, where we can
* have a whole strip in a single tile ... we still need to have a
* minimum of two strips, so we can handle requests that straddle a
* tile boundary.
*/
block_cache->max_tiles = 3 * n_lines / block_cache->tile_height;
block_cache->max_tiles = VIPS_MAX( 2,
3 * n_lines / block_cache->tile_height );

VIPS_DEBUG_MSG( "vips_line_cache_build: n_lines = %d\n",
n_lines );
Expand Down
4 changes: 3 additions & 1 deletion libvips/foreign/tiff2vips.c
Expand Up @@ -2049,6 +2049,9 @@ rtiff_read_stripwise( Rtiff *rtiff, VipsImage *out )

}

/* rows_per_strip can be very large if this is a separate plane image,
* beware.
*/
if(
vips_image_generate( t[0],
NULL, rtiff_stripwise_generate, NULL,
Expand All @@ -2059,7 +2062,6 @@ rtiff_read_stripwise( Rtiff *rtiff, VipsImage *out )
rtiff_autorotate( rtiff, t[1], &t[2] ) ||
rtiff_unpremultiply( rtiff, t[2], &t[3] ) ||
vips_image_write( t[3], out ) )

return( -1 );

return( 0 );
Expand Down

0 comments on commit 3887d8a

Please sign in to comment.