Skip to content

Commit d0429b5

Browse files
authored
fix(tiff): care with missing rowsperstrip (#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 19c4563 commit d0429b5

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
@@ -200,6 +200,7 @@ floor2(int x) noexcept
200200
template <typename V, typename M>
201201
inline OIIO_HOSTDEVICE V round_to_multiple (V value, M multiple)
202202
{
203+
OIIO_DASSERT(multiple > M(0));
203204
if (value >= 0)
204205
value += V(multiple) - 1;
205206
return value - (value % V(multiple));

src/tiff.imageio/tiffinput.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,14 @@ TIFFInput::readspec(bool read_meta)
13091309
m_rowsperstrip = -1;
13101310
if (!m_spec.tile_width) {
13111311
TIFFGetField(m_tif, TIFFTAG_ROWSPERSTRIP, &m_rowsperstrip);
1312-
if (m_rowsperstrip > 0)
1312+
if (m_rowsperstrip > 0) {
1313+
// Only set the attrib if a legit value was found in the file
13131314
m_spec.attribute("tiff:RowsPerStrip", m_rowsperstrip);
1315+
m_rowsperstrip = std::min(m_rowsperstrip, m_spec.height);
1316+
} else {
1317+
// Default if not found is "one strip for the whole image"
1318+
m_rowsperstrip = m_spec.height;
1319+
}
13141320
}
13151321

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

0 commit comments

Comments
 (0)