From 243b3b68556bfe9f3085c55cddf839bdedfe73ad Mon Sep 17 00:00:00 2001 From: Dharshan Vishwanatha <38626675+DharshanV@users.noreply.github.com> Date: Sun, 29 Sep 2024 01:56:31 +1000 Subject: [PATCH] int: Added check_open for PNG, JPEG, and EXR readers (#4452) This PR is ment to address this feature request: https://github.com/AcademySoftwareFoundation/OpenImageIO/issues/3974 I added `check_open` for these file format's ImageInput while following each file specfication: - PNG: https://www.w3.org/TR/png/#11IHDR - JPEG: https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_APP0_marker_segment - EXR: https://openexr.com/en/latest/OpenEXRFileLayout.html#header-attributes-all-files --------- Signed-off-by: Dharshan Vishwanatha --- src/jpeg.imageio/jpeginput.cpp | 3 +++ src/openexr.imageio/exrinput.cpp | 3 +++ src/png.imageio/pnginput.cpp | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/jpeg.imageio/jpeginput.cpp b/src/jpeg.imageio/jpeginput.cpp index b00f2d96b7..f2c302a353 100644 --- a/src/jpeg.imageio/jpeginput.cpp +++ b/src/jpeg.imageio/jpeginput.cpp @@ -253,6 +253,9 @@ JpgInput::open(const std::string& name, ImageSpec& newspec) m_spec = ImageSpec(m_cinfo.output_width, m_cinfo.output_height, nchannels, TypeDesc::UINT8); + if (!check_open(m_spec, { 0, 1 << 16, 0, 1 << 16, 0, 1, 0, 3 })) + return false; + // Assume JPEG is in sRGB unless the Exif or XMP tags say otherwise. m_spec.attribute("oiio:ColorSpace", "sRGB"); diff --git a/src/openexr.imageio/exrinput.cpp b/src/openexr.imageio/exrinput.cpp index 2085ada3a4..49796305d4 100644 --- a/src/openexr.imageio/exrinput.cpp +++ b/src/openexr.imageio/exrinput.cpp @@ -1024,6 +1024,9 @@ OpenEXRInput::seek_subimage(int subimage, int miplevel) m_miplevel = miplevel; m_spec = part.spec; + if (!check_open(m_spec, { 0, 1 << 20, 0, 1 << 20, 0, 1 << 16, 0, 1 << 12 })) + return false; + if (miplevel == 0 && part.levelmode == Imf::ONE_LEVEL) { return true; } diff --git a/src/png.imageio/pnginput.cpp b/src/png.imageio/pnginput.cpp index 71b31a78c2..748f22cb8c 100644 --- a/src/png.imageio/pnginput.cpp +++ b/src/png.imageio/pnginput.cpp @@ -162,7 +162,8 @@ PNGInput::open(const std::string& name, ImageSpec& newspec) bool ok = PNG_pvt::read_info(m_png, m_info, m_bit_depth, m_color_type, m_interlace_type, m_bg, m_spec, m_keep_unassociated_alpha); - if (!ok || m_err) { + if (!ok || m_err + || !check_open(m_spec, { 0, 1 << 16, 0, 1 << 16, 0, 1, 0, 4 })) { close(); return false; }