Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/libOpenImageIO/imageinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ static thread_local tsl::robin_map<uint64_t, std::string> input_error_messages;
static std::atomic_int64_t input_next_id(0);


static int
safe_rows_per_strip(const ImageSpec& spec)
{
int rps = spec.get_int_attribute("tiff:RowsPerStrip", 64);
return rps > 0 ? rps : 64;
}


class ImageInput::Impl {
public:
Impl()
Expand Down Expand Up @@ -365,7 +373,7 @@ ImageInput::read_scanlines(int subimage, int miplevel, int ybegin, int yend,
spec.copy_dimensions(m_spec);
// For scanline files, we also need one piece of metadata
if (!spec.tile_width)
rps = m_spec.get_int_attribute("tiff:RowsPerStrip", 64);
rps = safe_rows_per_strip(m_spec);
// FIXME: does the above search of metadata have a significant cost?
}
if (spec.image_bytes() < 1) {
Expand Down Expand Up @@ -1108,7 +1116,7 @@ ImageInput::read_image(int subimage, int miplevel, int chbegin, int chend,
spec.copy_dimensions(m_spec);
// For scanline files, we also need one piece of metadata
if (!spec.tile_width)
rps = m_spec.get_int_attribute("tiff:RowsPerStrip", 64);
rps = safe_rows_per_strip(m_spec);
}
if (spec.image_bytes() < 1) {
errorfmt("Invalid image size {} x {} ({} chans)", m_spec.width,
Expand Down Expand Up @@ -1201,7 +1209,7 @@ ImageInput::read_image(int subimage, int miplevel, int chbegin, int chend,
spec.copy_dimensions(m_spec);
// For scanline files, we also need one piece of metadata
if (!spec.tile_width)
rps = m_spec.get_int_attribute("tiff:RowsPerStrip", 64);
rps = safe_rows_per_strip(m_spec);
}
if (spec.image_bytes() < 1) {
errorfmt("Invalid image size {} x {} ({} chans)", m_spec.width,
Expand Down
12 changes: 11 additions & 1 deletion src/libOpenImageIO/imageoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@


OIIO_NAMESPACE_3_1_BEGIN


static int
safe_rows_per_strip(const ImageSpec& spec)
{
int rps = spec.get_int_attribute("tiff:RowsPerStrip", 64);
return rps > 0 ? rps : 64;
}


using namespace pvt;
using namespace OIIO::pvt;

Expand Down Expand Up @@ -665,7 +675,7 @@ ImageOutput::write_image(TypeDesc format, const void* data, stride_t xstride,
} else { // Scanline image
// Split into reasonable chunks -- try to use around 64 MB, but
// round up to a multiple of the TIFF rows per strip (or 64).
int rps = m_spec.get_int_attribute("tiff:RowsPerStrip", 64);
int rps = safe_rows_per_strip(m_spec);
int chunk = std::max(1, (1 << 26) / int(m_spec.scanline_bytes(true)));
chunk = round_to_multiple(chunk, rps);

Expand Down
14 changes: 14 additions & 0 deletions testsuite/invalid-rps-metadata/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Reading negrps.tif
negrps.tif : 1 x 1, 3 channel, float tiff
SHA-1: 2771C32B635C7C7154A48DBE4F54B3449ABC6B50
channel list: R, G, B
compression: "zip"
DateTime: "2026:07:03 07:11:01"
Orientation: 1 (normal)
planarconfig: "contig"
Software: "OpenImageIO 3.2.0.2dev : 2C50DDDC920616B428C03D5F6786B396201DAF23"
oiio:BitsPerSample: 32
tiff:Compression: 8
tiff:PhotometricInterpretation: 2
tiff:PlanarConfiguration: 1
tiff:RowsPerStrip: 32
13 changes: 13 additions & 0 deletions testsuite/invalid-rps-metadata/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

# save the error output
redirect = " >> out.txt 2>&1 "
failureok = 1

# command += oiiotool("-create 2x2 3 -d half -attrib tiff:RowsPerStrip -3 -o negrps.exr")
command += oiiotool("src/rowsperstrip-zero.exr -o negrps.tif")
command += info_command("negrps.tif", verbose=True, hash=True)
Binary file not shown.
Loading