Skip to content

Commit c6141da

Browse files
authored
Merge pull request openslide#706 from bgilbert/libtiff
tiff: fix corrupt non-JPEG partial bottom tile row on libtiff 4.7.1
2 parents 699ea36 + a4f0fb0 commit c6141da

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/openslide-decode-tiff.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,14 @@ bool _openslide_tiff_read_tile(struct _openslide_tiff_level *tiffl,
303303
_openslide_performance_warn_once(&tiffl->warned_read_indirect,
304304
"Using slow libtiff read path for "
305305
"directory %d", tiffl->dir);
306+
// artificially limit dest height so libtiff 4.7.1 won't unpad the
307+
// bottom row of tiles into the bottom pixels of dest
308+
// https://gitlab.com/libtiff/libtiff/-/issues/791
309+
uint32_t clipped_h =
310+
MIN(tiffl->tile_h, MAX(tiffl->image_h - tile_row * tiffl->tile_h, 0));
306311
return tiff_read_region(tiff, dest,
307312
tile_col * tiffl->tile_w, tile_row * tiffl->tile_h,
308-
tiffl->tile_w, tiffl->tile_h, err);
313+
tiffl->tile_w, clipped_h, err);
309314
}
310315
}
311316

292 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# libtiff 4.7.1 fails to initialize the relevant portion of the output
2+
# buffer if we try to fully read a partial bottom tile (not a JPEG one,
3+
# since we bypass libtiff for those). valgrind finds the problem but
4+
# sanitize doesn't.
5+
base: Generic-TIFF/CMU-1.tiff
6+
slide: CMU-1.tiff
7+
success: true
8+
vendor: generic-tiff
9+
regions:
10+
- [16, 16, 0, 8, 8]

0 commit comments

Comments
 (0)