Skip to content
Open
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
29 changes: 23 additions & 6 deletions src/cineon.imageio/cineoninput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CineonInput final : public ImageInput {
m_stream = nullptr;
}
m_userBuf.clear();
m_cin.SetInStream(nullptr);
}

/// Helper function - retrieve string for libcineon descriptor
Expand Down Expand Up @@ -89,12 +90,23 @@ CineonInput::open(const std::string& name, ImageSpec& newspec)
return false;
}

int nchannels = m_cin.header.NumberOfElements();
if (nchannels < 1 || nchannels > 8) {
errorfmt("Invalid number of channels {} (must be 1-8)", nchannels);
close();
return false;
}

// create imagespec
TypeDesc typedesc;
int maxbits = 0;
for (int i = 0; i < m_cin.header.NumberOfElements(); i++) {
if (maxbits < m_cin.header.BitDepth(i))
maxbits = m_cin.header.BitDepth(i);
for (int i = 0; i < nchannels; i++) {
int b(m_cin.header.BitDepth(i));
if (b < 1 || b > 32) {
errorfmt("Invalid bitdepth in channel {}: {} bits", i, b);
return false;
}
maxbits = std::max(maxbits, b);
}
switch ((maxbits + 7) / 8) {
case 1: typedesc = TypeDesc::UINT8; break;
Expand All @@ -103,8 +115,13 @@ CineonInput::open(const std::string& name, ImageSpec& newspec)
case 4: typedesc = TypeDesc::UINT32; break;
default: errorfmt("Unsupported bit depth {}", maxbits); return false;
}
m_spec = ImageSpec(m_cin.header.Width(), m_cin.header.Height(),
m_cin.header.NumberOfElements(), typedesc);
m_spec = ImageSpec(m_cin.header.Width(), m_cin.header.Height(), nchannels,
typedesc);

if (!check_open(m_spec, { 0, 1 << 20, 0, 1 << 20, 0, 1, 0, 8 })) {
return false;
}

// fill channel names
m_spec.channelnames.clear();
int gscount = 0, rcount = 0, gcount = 0, bcount = 0;
Expand All @@ -119,7 +136,7 @@ CineonInput::open(const std::string& name, ImageSpec& newspec)
break;
case cineon::kPrintingDensityRed:
case cineon::kRec709Red:
if (++gscount > 1) {
if (++rcount > 1) {
std::string ch = Strutil::fmt::format("R{}", rcount);
m_spec.channelnames.push_back(ch);
} else
Expand Down
3 changes: 3 additions & 0 deletions testsuite/cineon/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ Reading ../oiio-images/cineon/checker.cin
cineon:YOffset: 0
oiio:BitsPerSample: 10
oiio:ColorSpace: "KodakLog"
oiiotool ERROR: read : "src/broken_bitdepth.cin": Invalid number of channels 255 (must be 1-8)
Full command line was:
> oiiotool --info --hash src/broken_bitdepth.cin
8 changes: 8 additions & 0 deletions testsuite/cineon/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

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

files = [ "checker.cin" ]
for f in files:
command += info_command ("../oiio-images/cineon/" + f)


# Regression tests for broken files
command += info_command ("src/broken_bitdepth.cin", verbose=False, failureok=True)

outputs = [ "out.txt" ]
Binary file added testsuite/cineon/src/broken_bitdepth.cin
Binary file not shown.
Loading