Skip to content

Commit 32c668e

Browse files
committed
fix: more ICC protections against invalid tag sizes (#4565)
Signed-off-by: Larry Gritz <[email protected]>
1 parent 03587ec commit 32c668e

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

src/libOpenImageIO/icc.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,25 @@ decode_icc_profile(cspan<uint8_t> iccdata, ImageSpec& spec, std::string& error)
321321
if (typesignature == "text") {
322322
// For text, the first 4 bytes are "text", the next 4 are 0, then
323323
// byte 8-end are the zero-terminated string itself.
324+
if (tag.size < 8) {
325+
error = format(
326+
"ICC profile tag {} appears to contain corrupted/invalid data",
327+
signature);
328+
return false;
329+
}
324330
spec.attribute(tagname, string_view((const char*)iccdata.data()
325331
+ tag.offset + 8,
326332
tag.size - 8));
327333
} else if (typesignature == "desc") {
328334
// I don't see this in the spec, but I've seen it in practice:
329335
// first 4 bytes are "desc", next 8 are unknown, then 12-end are
330336
// zero-terminated string itself.
337+
if (tag.size < 12) {
338+
error = format(
339+
"ICC profile tag {} appears to contain corrupted/invalid data",
340+
signature);
341+
return false;
342+
}
331343
spec.attribute(tagname, string_view((const char*)iccdata.data()
332344
+ tag.offset + 12,
333345
tag.size - 12));

testsuite/jpeg-corrupt/ref/out-alt2.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,27 @@ src/corrupt-exif-1626.jpg : 256 x 256, 3 channel, uint8 jpeg
2020
oiio:ColorSpace: "sRGB"
2121
corrupt-icc-4551.jpg
2222
DCT coefficient (lossy) or spatial difference (lossless) out of range
23+
Reading src/corrupt-icc-4552.jpg
24+
src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
25+
SHA-1: 58BC613FDC7513B4F3854D8D2910040B60FF7A7F
26+
channel list: R, G, B
27+
ICCProfile: 0, 0, 12, 72, 76, 105, 110, 111, 2, 16, 0, 0, 109, 110, 116, 114, ... [3144 x uint8]
28+
ResolutionUnit: "in"
29+
XResolution: 72
30+
YResolution: 72
31+
ICCProfile:attributes: "Transparency , Glossy, Positive, Color"
32+
ICCProfile:cmm_type: 1281977967
33+
ICCProfile:color_space: "RGB"
34+
ICCProfile:creation_date: "1998:02:09 06:49:00"
35+
ICCProfile:creator_signature: "48502020"
36+
ICCProfile:device_class: "Display device profile"
37+
ICCProfile:flags: "Not Embedded, Independent"
38+
ICCProfile:manufacturer: "49454320"
39+
ICCProfile:model: "73524742"
40+
ICCProfile:platform_signature: "Microsoft Corporation"
41+
ICCProfile:profile_connection_space: "XYZ"
42+
ICCProfile:profile_size: 3144
43+
ICCProfile:profile_version: "2.1.0"
44+
ICCProfile:rendering_intent: "Unknown"
45+
jpeg:subsampling: "4:2:0"
46+
oiio:ColorSpace: "sRGB"

testsuite/jpeg-corrupt/ref/out-alt3.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ src/corrupt-exif-1626.jpg : 256 x 256, 3 channel, uint8 jpeg
1919
jpeg:subsampling: "4:2:0"
2020
oiio:ColorSpace: "sRGB"
2121
corrupt-icc-4551.jpg
22+
Reading src/corrupt-icc-4552.jpg
23+
src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
24+
SHA-1: 58BC613FDC7513B4F3854D8D2910040B60FF7A7F
25+
channel list: R, G, B
26+
ICCProfile: 0, 0, 12, 72, 76, 105, 110, 111, 2, 16, 0, 0, 109, 110, 116, 114, ... [3144 x uint8]
27+
ResolutionUnit: "in"
28+
XResolution: 72
29+
YResolution: 72
30+
ICCProfile:attributes: "Transparency , Glossy, Positive, Color"
31+
ICCProfile:cmm_type: 1281977967
32+
ICCProfile:color_space: "RGB"
33+
ICCProfile:creation_date: "1998:02:09 06:49:00"
34+
ICCProfile:creator_signature: "48502020"
35+
ICCProfile:device_class: "Display device profile"
36+
ICCProfile:flags: "Not Embedded, Independent"
37+
ICCProfile:manufacturer: "49454320"
38+
ICCProfile:model: "73524742"
39+
ICCProfile:platform_signature: "Microsoft Corporation"
40+
ICCProfile:profile_connection_space: "XYZ"
41+
ICCProfile:profile_size: 3144
42+
ICCProfile:profile_version: "2.1.0"
43+
ICCProfile:rendering_intent: "Unknown"
44+
jpeg:subsampling: "4:2:0"
45+
oiio:ColorSpace: "sRGB"

testsuite/jpeg-corrupt/ref/out.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,27 @@ src/corrupt-exif-1626.jpg : 256 x 256, 3 channel, uint8 jpeg
2020
oiio:ColorSpace: "sRGB"
2121
corrupt-icc-4551.jpg
2222
DCT coefficient (lossy) or spatial difference (lossless) out of range
23+
Reading src/corrupt-icc-4552.jpg
24+
src/corrupt-icc-4552.jpg : 1500 x 1000, 3 channel, uint8 jpeg
25+
SHA-1: 58BC613FDC7513B4F3854D8D2910040B60FF7A7F
26+
channel list: R, G, B
27+
ICCProfile: 0, 0, 12, 72, 76, 105, 110, 111, 2, 16, 0, 0, 109, 110, 116, 114, ... [3144 x uint8]
28+
ResolutionUnit: "in"
29+
XResolution: 72
30+
YResolution: 72
31+
ICCProfile:attributes: "Transparency , Glossy, Positive, Color"
32+
ICCProfile:cmm_type: 1281977967
33+
ICCProfile:color_space: "RGB"
34+
ICCProfile:creation_date: "1998:02:09 06:49:00"
35+
ICCProfile:creator_signature: "48502020"
36+
ICCProfile:device_class: "Display device profile"
37+
ICCProfile:flags: "Not Embedded, Independent"
38+
ICCProfile:manufacturer: "49454320"
39+
ICCProfile:model: "73524742"
40+
ICCProfile:platform_signature: "Microsoft Corporation"
41+
ICCProfile:profile_connection_space: "XYZ"
42+
ICCProfile:profile_size: 3144
43+
ICCProfile:profile_version: "2.1.0"
44+
ICCProfile:rendering_intent: "Unknown"
45+
jpeg:subsampling: "4:2:0"
46+
oiio:ColorSpace: "sRGB"

testsuite/jpeg-corrupt/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
# extend beyond the boundaries of the ICC block itself.
2222
command += run_app (oiiotool("--echo corrupt-icc-4551.jpg"))
2323
command += run_app (oiio_app("iconvert") + " src/corrupt-icc-4551.jpg out-4551.jpg")
24+
25+
# This file has a corrupted ICC profile block
26+
command += info_command ("src/corrupt-icc-4552.jpg", safematch=True)
3.44 KB
Loading

0 commit comments

Comments
 (0)