Skip to content
Open
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
17 changes: 12 additions & 5 deletions src/ico.imageio/icoinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ICOInput final : public ImageInput {
int m_color_type; ///< PNG color model type
int m_interlace_type; ///< PNG interlace type
Imath::Color3f m_bg; ///< PNG background color
bool m_err = false;

/// Reset everything to initial state
///
Expand All @@ -65,6 +66,7 @@ class ICOInput final : public ImageInput {
m_subimage = -1;
m_png = NULL;
m_info = NULL;
m_err = false;
memset(&m_ico, 0, sizeof(m_ico));
m_buf.clear();
ioproxy_clear();
Expand All @@ -81,6 +83,7 @@ class ICOInput final : public ImageInput {
ICOInput* icoinput = (ICOInput*)png_get_io_ptr(png_ptr);
OIIO_DASSERT(icoinput);
if (!icoinput->ioread(data, length)) {
icoinput->m_err = true;
png_chunk_error(png_ptr, icoinput->geterror(false).c_str());
}
}
Expand Down Expand Up @@ -231,11 +234,15 @@ ICOInput::seek_subimage(int subimage, int miplevel)

png_set_sig_bytes(m_png, 8); // already read 8 bytes

if (!PNG_pvt::read_info(m_png, m_info, m_bpp, m_color_type,
m_interlace_type, m_bg, m_spec, true))
return false;
if (!check_open(m_spec, { 0, 1 << 20, 0, 1 << 20, 0, 1, 0, 4 }))
bool ok = PNG_pvt::read_info(m_png, m_info, m_bpp, m_color_type,
m_interlace_type, m_bg, m_spec, true);
if (!ok || m_err
|| !check_open(m_spec, { 0, 256, 0, 256, 0, 1, 0, 4 })) {
// Technically, PNGs can be bigger, but we think nobody will make
// ICO files (even those that are png underneath) this big, so
// assume anything over 2^16 res is bogus.
return false;
}

m_spec.attribute("oiio:BitsPerSample", m_bpp / m_spec.nchannels);

Expand Down Expand Up @@ -312,7 +319,7 @@ ICOInput::readimg()

//std::cerr << "[ico] PNG buffer size = " << m_buf.size () << "\n";

if (s.length()) {
if (s.length() || m_err || has_error()) {
errorfmt("{}", s);
return false;
}
Expand Down
Loading