From c646a72d946c57cba628b6faac17a5d9327904c3 Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Sat, 20 Apr 2024 21:14:35 +0200 Subject: [PATCH] Add more checks for crafted CGATS Improve non-happy path --- src/cmscgats.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cmscgats.c b/src/cmscgats.c index 657e76e1..835bae87 100644 --- a/src/cmscgats.c +++ b/src/cmscgats.c @@ -1210,6 +1210,8 @@ void* AllocChunk(cmsIT8* it8, cmsUInt32Number size) if (size > Free) { + cmsUInt8Number* new_block; + if (it8 -> Allocator.BlockSize == 0) it8 -> Allocator.BlockSize = 20*1024; @@ -1220,7 +1222,11 @@ void* AllocChunk(cmsIT8* it8, cmsUInt32Number size) it8 ->Allocator.BlockSize = size; it8 ->Allocator.Used = 0; - it8 ->Allocator.Block = (cmsUInt8Number*) AllocBigBlock(it8, it8 ->Allocator.BlockSize); + new_block = (cmsUInt8Number*)AllocBigBlock(it8, it8->Allocator.BlockSize); + if (new_block == NULL) + return NULL; + + it8->Allocator.Block = new_block; } if (it8->Allocator.Block == NULL) @@ -1230,7 +1236,6 @@ void* AllocChunk(cmsIT8* it8, cmsUInt32Number size) it8 ->Allocator.Used += size; return (void*) ptr; - } @@ -1732,7 +1737,10 @@ char* GetData(cmsIT8* it8, int nSet, int nField) static cmsBool SetData(cmsIT8* it8, int nSet, int nField, const char *Val) { + char* ptr; + TABLE* t = GetTable(it8); + if (!t->Data) { if (!AllocateDataSet(it8)) return FALSE; @@ -1750,7 +1758,11 @@ cmsBool SetData(cmsIT8* it8, int nSet, int nField, const char *Val) } - t->Data [nSet * t -> nSamples + nField] = AllocString(it8, Val); + ptr = AllocString(it8, Val); + if (ptr == NULL) + return FALSE; + + t->Data [nSet * t -> nSamples + nField] = ptr; return TRUE; }