Skip to content

Commit a39e39f

Browse files
committed
Fix for #469 heap buffer overflow on convert_utf16_to_utf32()
Many thanks to @GPTFuzzx for pointing out the issue.
1 parent e62798d commit a39e39f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/cmstypes.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,8 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
11111111

11121112
// Read len of ASCII
11131113
if (!_cmsReadUInt32Number(io, &AsciiCount)) return NULL;
1114+
if (AsciiCount > 0x7ffff) return NULL;
1115+
11141116
SizeOfTag -= sizeof(cmsUInt32Number);
11151117

11161118
// Check for size
@@ -1141,8 +1143,9 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
11411143
if (!_cmsReadUInt32Number(io, &UnicodeCode)) goto Done;
11421144
if (!_cmsReadUInt32Number(io, &UnicodeCount)) goto Done;
11431145
SizeOfTag -= 2* sizeof(cmsUInt32Number);
1144-
1145-
if (UnicodeCount == 0 || SizeOfTag < UnicodeCount*sizeof(cmsUInt16Number)) goto Done;
1146+
1147+
if (UnicodeCount == 0 || UnicodeCount > 0x7ffff ||
1148+
SizeOfTag < UnicodeCount*sizeof(cmsUInt16Number)) goto Done;
11461149

11471150
UnicodeString = (wchar_t*)_cmsMallocZero(self->ContextID, (UnicodeCount + 1) * sizeof(wchar_t));
11481151
if (UnicodeString == NULL) goto Done;
@@ -5334,7 +5337,7 @@ cmsBool ReadOneWChar(cmsIOHANDLER* io, _cmsDICelem* e, cmsUInt32Number i, wchar
53345337
if (!io -> Seek(io, e -> Offsets[i])) return FALSE;
53355338

53365339
nChars = e ->Sizes[i] / sizeof(cmsUInt16Number);
5337-
5340+
if (nChars > 0x7ffff) return FALSE;
53385341

53395342
*wcstr = (wchar_t*) _cmsMallocZero(e ->ContextID, (nChars + 1) * sizeof(wchar_t));
53405343
if (*wcstr == NULL) return FALSE;

0 commit comments

Comments
 (0)