diff --git a/src/cmslut.c b/src/cmslut.c index 383f05c9..1ea61a80 100644 --- a/src/cmslut.c +++ b/src/cmslut.c @@ -817,7 +817,13 @@ cmsBool CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler cmsUInt32Number nInputs, nOutputs; cmsUInt32Number* nSamples; cmsFloat32Number In[MAX_INPUT_DIMENSIONS+1], Out[MAX_STAGE_CHANNELS]; - _cmsStageCLutData* clut = (_cmsStageCLutData*) mpe->Data; + _cmsStageCLutData* clut; + + if (mpe == NULL) return FALSE; + + clut = (_cmsStageCLutData*)mpe->Data; + + if (clut == NULL) return FALSE; nSamples = clut->Params ->nSamples; nInputs = clut->Params ->nInputs; diff --git a/src/cmsopt.c b/src/cmsopt.c index ad2c9c01..4038088b 100644 --- a/src/cmsopt.c +++ b/src/cmsopt.c @@ -1728,6 +1728,8 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 _cmsStageMatrixData* Data = (_cmsStageMatrixData*)cmsStageData(Matrix1); + if (Matrix1->InputChannels != 3 || Matrix1->OutputChannels != 3) return FALSE; + // Copy the matrix to our result memcpy(&res, Data->Double, sizeof(res)); diff --git a/src/cmstypes.c b/src/cmstypes.c index 587c717c..0debda97 100644 --- a/src/cmstypes.c +++ b/src/cmstypes.c @@ -1919,7 +1919,7 @@ void *Type_LUT8_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cms // We only allow a specific MPE structure: Matrix plus prelin, plus clut, plus post-lin. static -cmsBool Type_LUT8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) +cmsBool Type_LUT8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) { cmsUInt32Number j, nTabSize, i; cmsUInt8Number val; @@ -1932,6 +1932,12 @@ cmsBool Type_LUT8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, // Disassemble the LUT into components. mpe = NewLUT -> Elements; + + if (mpe == NULL) { // Should never be empty. Corrupted? + cmsSignalError(self->ContextID, cmsERROR_UNKNOWN_EXTENSION, "empty LUT8 is not supported"); + return FALSE; + } + if (mpe ->Type == cmsSigMatrixElemType) { if (mpe->InputChannels != 3 || mpe->OutputChannels != 3) return FALSE;