From e086f4b35b1adf7edc35b4ad332dc7ed1edc5988 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Mon, 25 Mar 2019 16:28:54 +0100 Subject: [PATCH] Add bound check in datafile.cpp anywhere m_ppDataPtrs is accessed as an array. Should fix #2073 --- src/engine/shared/datafile.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp index 04704db38..190b56686 100644 --- a/src/engine/shared/datafile.cpp +++ b/src/engine/shared/datafile.cpp @@ -249,6 +249,9 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap) { if(!m_pDataFile) { return 0; } + if(Index < 0 || Index >= m_pDataFile->m_Header.m_NumRawData) + return 0; + // load it if needed if(!m_pDataFile->m_ppDataPtrs[Index]) { @@ -312,6 +315,9 @@ void *CDataFileReader::GetDataSwapped(int Index) 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 GetDataImpl(Index, 0); @@ -321,10 +327,9 @@ void CDataFileReader::ReplaceData(int Index, char *pData) void CDataFileReader::UnloadData(int Index) { - if(Index < 0) + if(Index < 0 || Index >= m_pDataFile->m_Header.m_NumRawData) return; - // mem_free(m_pDataFile->m_ppDataPtrs[Index]); m_pDataFile->m_ppDataPtrs[Index] = 0x0; }