Skip to content

Commit

Permalink
Be more strict on number of fields
Browse files Browse the repository at this point in the history
Perform some extra checks to prevent crafted IT8
  • Loading branch information
mm2 committed Apr 16, 2024
1 parent 1176e61 commit fe8d383
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/cmscgats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ void* AllocChunk(cmsIT8* it8, cmsUInt32Number size)
cmsUInt8Number* ptr;

size = _cmsALIGNMEM(size);
if (size == 0) return NULL;

if (size > Free) {

Expand Down Expand Up @@ -1598,22 +1599,26 @@ cmsInt32Number satoi(const char* b)
static
cmsBool AllocateDataFormat(cmsIT8* it8)
{
cmsUInt32Number size;

TABLE* t = GetTable(it8);

if (t -> DataFormat) return TRUE; // Already allocated
if (t->DataFormat) return TRUE; // Already allocated

t -> nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
t->nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));

if (t -> nSamples <= 0) {
if (t->nSamples <= 0 || t->nSamples > 0x7ffe) {

SynError(it8, "AllocateDataFormat: Unknown NUMBER_OF_FIELDS");
return FALSE;
}
SynError(it8, "Wrong NUMBER_OF_FIELDS");
return FALSE;
}

size = ((cmsUInt32Number)t->nSamples + 1) * sizeof(char*);

t -> DataFormat = (char**) AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * sizeof(char *));
t->DataFormat = (char**)AllocChunk(it8, size);
if (t->DataFormat == NULL) {

SynError(it8, "AllocateDataFormat: Unable to allocate dataFormat array");
SynError(it8, "Unable to allocate dataFormat array");
return FALSE;
}

Expand Down Expand Up @@ -1642,7 +1647,7 @@ cmsBool SetDataFormat(cmsIT8* it8, int n, const char *label)
return FALSE;
}

if (n > t -> nSamples) {
if (n >= t -> nSamples) {
SynError(it8, "More than NUMBER_OF_FIELDS fields.");
return FALSE;
}
Expand Down

0 comments on commit fe8d383

Please sign in to comment.