Skip to content

Commit 43ae18d

Browse files
authored
Fix: SIO in bool parse3DTable() (#611)
Signed-off-by: David Hoyt <dhoyt@hoyt.net>
1 parent 29d0888 commit 43ae18d

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

IccProfLib/IccTagLut.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,8 @@ bool CIccCLUT::Init(icUInt8Number nGridPoints, icUInt32Number nMaxSize, icUInt8N
18331833
// m_GridPoints[] is a fixed length of 16
18341834
if (m_nInput > 16)
18351835
return false;
1836+
if (nGridPoints < 2) // at least 2 required for interpolation to work
1837+
return false;
18361838
memset(m_GridPoints, nGridPoints, m_nInput);
18371839
return Init(&m_GridPoints[0], nMaxSize, nBytesPerPoint);
18381840
}

Tools/CmdLine/IccFromCube/iccFromCube.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
#include <cstdio>
7373
#include <string>
74+
#include <climits>
7475
#include "IccProfile.h"
7576
#include "IccTagBasic.h"
7677
#include "IccTagMPE.h"
@@ -144,7 +145,10 @@ class CubeFile
144145
return false;
145146
}
146147
else if (line.substr(0, 12) == "LUT_3D_SIZE ") {
147-
m_sizeLut3D = atoi(line.c_str() + 12);
148+
int64_t temp = atoll( line.c_str() + 12 );
149+
if (temp >= INT_MAX || temp <= 0)
150+
return false;
151+
m_sizeLut3D = (int)temp;
148152
}
149153
else if (line.substr(0, 19) == "LUT_3D_INPUT_RANGE ") {
150154
m_fMinInput[0] = m_fMinInput[1] = m_fMinInput[2] = (icFloatNumber)atof(line.c_str() + 19);
@@ -215,10 +219,15 @@ class CubeFile
215219
int sizeLut3D() { return m_sizeLut3D; }
216220
bool parse3DTable(icFloatNumber* toLut, icUInt32Number nSizeLut)
217221
{
218-
icUInt32Number num = m_sizeLut3D * m_sizeLut3D * m_sizeLut3D;
222+
if (m_sizeLut3D < 2 || nSizeLut <= 0)
223+
return false;
224+
225+
uint64_t temp = (uint64_t)m_sizeLut3D * (uint64_t)m_sizeLut3D * (uint64_t)m_sizeLut3D;
226+
if (temp > UINT_MAX)
227+
return false;
228+
icUInt32Number num = (icUInt32Number)temp;
219229

220-
//
221-
if (!m_sizeLut3D || nSizeLut != num*3)
230+
if (nSizeLut != num*3)
222231
return false;
223232

224233
const char* next;
@@ -406,8 +415,17 @@ int main(int argc, char* argv[])
406415

407416
CIccMpeCLUT* pMpeCLUT = new CIccMpeCLUT();
408417
CIccCLUT* pCLUT = new CIccCLUT(3, 3);
409-
pCLUT->Init(cube.sizeLut3D());
418+
419+
if (!pCLUT->Init(cube.sizeLut3D()) ) {
420+
printf("Unable to create LUT from '%s'\n", argv[1]);
421+
return -4;
422+
}
423+
410424
bool bSuccess = cube.parse3DTable(pCLUT->GetData(0), pCLUT->NumPoints()*3);
425+
if (!bSuccess) {
426+
printf("Unable to parse LUT from '%s'\n", argv[1]);
427+
return (-4);
428+
}
411429

412430
pMpeCLUT->SetCLUT(pCLUT);
413431
pTag->Attach(pMpeCLUT);
@@ -416,11 +434,6 @@ int main(int argc, char* argv[])
416434

417435
cube.close();
418436

419-
if (!bSuccess) {
420-
printf("Unable to parse LUT from '%s'\n", argv[1]);
421-
return (-4);
422-
}
423-
424437
//Add description Tag
425438
CIccTagMultiLocalizedUnicode* pTextTag = new CIccTagMultiLocalizedUnicode();
426439
std::string desc = cube.getDescription();

0 commit comments

Comments
 (0)