Add bound check in datafile.cpp anywhere m_ppDataPtrs is accessed as an array. Should fix #2073

This commit is contained in:
Jordy Ruiz 2019-03-25 16:28:54 +01:00
parent d25869626a
commit e086f4b35b

View file

@ -249,6 +249,9 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
{ {
if(!m_pDataFile) { return 0; } if(!m_pDataFile) { return 0; }
if(Index < 0 || Index >= m_pDataFile->m_Header.m_NumRawData)
return 0;
// load it if needed // load it if needed
if(!m_pDataFile->m_ppDataPtrs[Index]) if(!m_pDataFile->m_ppDataPtrs[Index])
{ {
@ -312,6 +315,9 @@ void *CDataFileReader::GetDataSwapped(int Index)
void CDataFileReader::ReplaceData(int Index, char *pData) void CDataFileReader::ReplaceData(int Index, char *pData)
{ {
if(Index < 0 || Index >= m_pDataFile->m_Header.m_NumRawData)
return;
// make sure the data has been loaded // make sure the data has been loaded
GetDataImpl(Index, 0); GetDataImpl(Index, 0);
@ -321,10 +327,9 @@ void CDataFileReader::ReplaceData(int Index, char *pData)
void CDataFileReader::UnloadData(int Index) void CDataFileReader::UnloadData(int Index)
{ {
if(Index < 0) if(Index < 0 || Index >= m_pDataFile->m_Header.m_NumRawData)
return; return;
//
mem_free(m_pDataFile->m_ppDataPtrs[Index]); mem_free(m_pDataFile->m_ppDataPtrs[Index]);
m_pDataFile->m_ppDataPtrs[Index] = 0x0; m_pDataFile->m_ppDataPtrs[Index] = 0x0;
} }