Skip to content

Commit 4065e6f

Browse files
authored
fix(ico): More robust to corrupted ICO files (#4625)
Signed-off-by: Larry Gritz <[email protected]>
1 parent bfa48c8 commit 4065e6f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

src/ico.imageio/icoinput.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ ICOInput::seek_subimage(int subimage, int miplevel)
190190
swap_endian(&subimg.numColours);
191191
}
192192

193+
// some sanity checking
194+
if (subimg.bpp != 1 && subimg.bpp != 4 && subimg.bpp != 8
195+
&& subimg.bpp != 16 && subimg.bpp != 24 && subimg.bpp != 32) {
196+
errorfmt("Unsupported image color depth, probably corrupt file");
197+
return false;
198+
}
199+
if (subimg.reserved != 0) {
200+
errorfmt(
201+
"Probably corrupt file (clue: header 'reserved' value should always be 0)",
202+
subimg.reserved);
203+
return false;
204+
}
205+
193206
ioseek(subimg.ofs, SEEK_SET);
194207

195208
// test for a PNG icon

testsuite/ico/ref/out.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ Reading ../oiio-images/ico/oiio.ico
4545
oiio:BitsPerSample: 8
4646
Comparing "../oiio-images/ico/oiio.ico" and "oiio.ico"
4747
PASS
48+
iconvert ERROR: Unsupported image color depth, probably corrupt file

testsuite/ico/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
# SPDX-License-Identifier: Apache-2.0
55
# https://github.com/AcademySoftwareFoundation/OpenImageIO
66

7-
command = rw_command (OIIO_TESTSUITE_IMAGEDIR, "oiio.ico")
7+
failureok = 1
8+
redirect = ' >> out.txt 2>&1 '
9+
10+
command += rw_command (OIIO_TESTSUITE_IMAGEDIR, "oiio.ico")
11+
command += run_app (oiio_app("iconvert") + " src/bad1.ico out.tif")
12+

testsuite/ico/src/bad1.ico

69 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)