Skip to content

Commit 81f22d4

Browse files
committed
fix(tiff): care with missing rowsperstrip (AcademySoftwareFoundation#5160)
According to the TIFF spec, TIFF files with a missing rowsperstrip should assume the whole image is one strip. Somewhat related (found in debugging): add a DASSERT to help debug if fmath.h's round_to_multiple() is given an invalid denominator. --------- Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 505e2da commit 81f22d4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/include/OpenImageIO/fmath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ floor2(int x) noexcept
190190
template <typename V, typename M>
191191
inline OIIO_HOSTDEVICE V round_to_multiple (V value, M multiple)
192192
{
193+
OIIO_DASSERT(multiple > M(0));
193194
if (value >= 0)
194195
value += V(multiple) - 1;
195196
return value - (value % V(multiple));

src/tiff.imageio/tiffinput.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,14 @@ TIFFInput::readspec(bool read_meta)
11211121
m_rowsperstrip = -1;
11221122
if (!m_spec.tile_width) {
11231123
TIFFGetField(m_tif, TIFFTAG_ROWSPERSTRIP, &m_rowsperstrip);
1124-
if (m_rowsperstrip > 0)
1124+
if (m_rowsperstrip > 0) {
1125+
// Only set the attrib if a legit value was found in the file
11251126
m_spec.attribute("tiff:RowsPerStrip", m_rowsperstrip);
1127+
m_rowsperstrip = std::min(m_rowsperstrip, m_spec.height);
1128+
} else {
1129+
// Default if not found is "one strip for the whole image"
1130+
m_rowsperstrip = m_spec.height;
1131+
}
11261132
}
11271133

11281134
// The libtiff docs say that only uncompressed images, or those with

0 commit comments

Comments
 (0)