diff --git a/src/ico.imageio/icoinput.cpp b/src/ico.imageio/icoinput.cpp index 44cda26001..c0fe860036 100644 --- a/src/ico.imageio/icoinput.cpp +++ b/src/ico.imageio/icoinput.cpp @@ -190,6 +190,19 @@ ICOInput::seek_subimage(int subimage, int miplevel) swap_endian(&subimg.numColours); } + // some sanity checking + if (subimg.bpp != 1 && subimg.bpp != 4 && subimg.bpp != 8 + && subimg.bpp != 16 && subimg.bpp != 24 && subimg.bpp != 32) { + errorfmt("Unsupported image color depth, probably corrupt file"); + return false; + } + if (subimg.reserved != 0) { + errorfmt( + "Probably corrupt file (clue: header 'reserved' value should always be 0)", + subimg.reserved); + return false; + } + ioseek(subimg.ofs, SEEK_SET); // test for a PNG icon diff --git a/testsuite/ico/ref/out.txt b/testsuite/ico/ref/out.txt index 6272454fe8..b78639c7ee 100644 --- a/testsuite/ico/ref/out.txt +++ b/testsuite/ico/ref/out.txt @@ -45,3 +45,4 @@ Reading ../oiio-images/ico/oiio.ico oiio:BitsPerSample: 8 Comparing "../oiio-images/ico/oiio.ico" and "oiio.ico" PASS +iconvert ERROR: Unsupported image color depth, probably corrupt file diff --git a/testsuite/ico/run.py b/testsuite/ico/run.py index a329ce1790..44df1bda9b 100755 --- a/testsuite/ico/run.py +++ b/testsuite/ico/run.py @@ -4,4 +4,9 @@ # SPDX-License-Identifier: Apache-2.0 # https://github.com/AcademySoftwareFoundation/OpenImageIO -command = rw_command (OIIO_TESTSUITE_IMAGEDIR, "oiio.ico") +failureok = 1 +redirect = ' >> out.txt 2>&1 ' + +command += rw_command (OIIO_TESTSUITE_IMAGEDIR, "oiio.ico") +command += run_app (oiio_app("iconvert") + " src/bad1.ico out.tif") + diff --git a/testsuite/ico/src/bad1.ico b/testsuite/ico/src/bad1.ico new file mode 100644 index 0000000000..31725f57e1 Binary files /dev/null and b/testsuite/ico/src/bad1.ico differ