Skip to content

Commit

Permalink
Fix some bugs introduced by last localization commit
Browse files Browse the repository at this point in the history
On adding a zero terminator and free memory on error
  • Loading branch information
mm2 committed Nov 5, 2023
1 parent 5262c5d commit 178d734
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cmstypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,18 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
if (!_cmsReadUInt32Number(io, &UnicodeCount)) goto Done;
SizeOfTag -= 2* sizeof(cmsUInt32Number);

if (SizeOfTag < UnicodeCount*sizeof(cmsUInt16Number)) goto Done;
if (UnicodeCount == 0 || SizeOfTag < UnicodeCount*sizeof(cmsUInt16Number)) goto Done;

UnicodeString = (wchar_t*)_cmsMalloc(self->ContextID, UnicodeCount * sizeof(wchar_t));
UnicodeString = (wchar_t*)_cmsMalloc(self->ContextID, (UnicodeCount + 1) * sizeof(wchar_t));
if (UnicodeString == NULL) goto Done;

if (!_cmsReadWCharArray(io, UnicodeCount, UnicodeString)) goto Done;

UnicodeString[UnicodeCount] = 0;

if (!cmsMLUsetWide(mlu, cmsV2Unicode, cmsV2Unicode, UnicodeString)) goto Done;
_cmsFree(self->ContextID, (void*)UnicodeString);
UnicodeString = NULL;

SizeOfTag -= UnicodeCount*sizeof(cmsUInt16Number);

Expand All @@ -1002,6 +1006,7 @@ void *Type_Text_Description_Read(struct _cms_typehandler_struct* self, cmsIOHAND
return mlu;

Error:
if (UnicodeString) _cmsFree(self->ContextID, (void*)UnicodeString);
if (Text) _cmsFree(self ->ContextID, (void*) Text);
if (mlu) cmsMLUfree(mlu);
return NULL;
Expand Down

0 comments on commit 178d734

Please sign in to comment.