Skip to content

Commit

Permalink
fix(ico): More robust to corrupted ICO files (AcademySoftwareFoundati…
Browse files Browse the repository at this point in the history
…on#4625)

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Feb 14, 2025
1 parent bfa48c8 commit 4065e6f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/ico.imageio/icoinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testsuite/ico/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion testsuite/ico/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Binary file added testsuite/ico/src/bad1.ico
Binary file not shown.

0 comments on commit 4065e6f

Please sign in to comment.