From 47e5e0aced099800cb93a8441d3d5ab33240d23e Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Thu, 21 Dec 2023 22:35:08 +0100 Subject: Fixed https://github.com/ladislav-zezula/StormLib/issues/311 --- src/SFileGetFileInfo.cpp | 14 ++++++++++++++ src/SFileOpenFileEx.cpp | 13 ++++++------- src/StormLib.h | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/SFileGetFileInfo.cpp b/src/SFileGetFileInfo.cpp index 7a8afe0..20f5e75 100644 --- a/src/SFileGetFileInfo.cpp +++ b/src/SFileGetFileInfo.cpp @@ -68,6 +68,10 @@ static bool GetInfo_BufferCheck(void * pvFileInfo, DWORD cbFileInfo, DWORD cbDat static bool GetInfo(void * pvFileInfo, DWORD cbFileInfo, const void * pvData, DWORD cbData, LPDWORD pcbLengthNeeded) { + // Verify the input parameter + if(pvData == NULL) + return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + // Verify buffer pointer and buffer size if(!GetInfo_BufferCheck(pvFileInfo, cbFileInfo, cbData, pcbLengthNeeded)) return false; @@ -81,6 +85,10 @@ static bool GetInfo_Allocated(void * pvFileInfo, DWORD cbFileInfo, void * pvData { bool bResult; + // Verify the input parameter + if(pvData == NULL) + return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); + // Verify buffer pointer and buffer size if((bResult = GetInfo_BufferCheck(pvFileInfo, cbFileInfo, cbData, pcbLengthNeeded)) != false) memcpy(pvFileInfo, pvData, cbData); @@ -401,15 +409,21 @@ bool WINAPI SFileGetFileInfo( return GetInfo(pvFileInfo, cbFileInfo, &hf->dwHashIndex, sizeof(DWORD), pcbLengthNeeded); case SFileInfoNameHash1: + if(hf->pHashEntry == NULL) + return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); return GetInfo(pvFileInfo, cbFileInfo, &hf->pHashEntry->dwName1, sizeof(DWORD), pcbLengthNeeded); case SFileInfoNameHash2: + if(hf->pHashEntry == NULL) + return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); return GetInfo(pvFileInfo, cbFileInfo, &hf->pHashEntry->dwName2, sizeof(DWORD), pcbLengthNeeded); case SFileInfoNameHash3: return GetInfo(pvFileInfo, cbFileInfo, &pFileEntry->FileNameHash, sizeof(ULONGLONG), pcbLengthNeeded); case SFileInfoLocale: + if(hf->pHashEntry == NULL) + return GetInfo_ReturnError(ERROR_INVALID_PARAMETER); dwInt32Value = SFILE_MAKE_LCID(hf->pHashEntry->Locale, hf->pHashEntry->Platform); return GetInfo(pvFileInfo, cbFileInfo, &dwInt32Value, sizeof(DWORD), pcbLengthNeeded); diff --git a/src/SFileOpenFileEx.cpp b/src/SFileOpenFileEx.cpp index b5829b4..d26e01e 100644 --- a/src/SFileOpenFileEx.cpp +++ b/src/SFileOpenFileEx.cpp @@ -20,7 +20,6 @@ static DWORD FindHashIndex(TMPQArchive * ha, DWORD dwFileIndex) { TMPQHash * pHashTableEnd; TMPQHash * pHash; - DWORD dwFirstIndex = HASH_ENTRY_FREE; // Should only be called if the archive has hash table assert(ha->pHashTable != NULL); @@ -32,15 +31,15 @@ static DWORD FindHashIndex(TMPQArchive * ha, DWORD dwFileIndex) { if(MPQ_BLOCK_INDEX(pHash) == dwFileIndex) { - // Duplicate hash entry found - if(dwFirstIndex != HASH_ENTRY_FREE) - return HASH_ENTRY_FREE; - dwFirstIndex = (DWORD)(pHash - ha->pHashTable); + // Find the first hash entry that points to it. + // If there are multiple hash entries that point + // to the same file, only the first one is returned. + return (DWORD)(pHash - ha->pHashTable); } } - // Return the hash table entry index - return dwFirstIndex; + // No item was found + return HASH_ENTRY_FREE; } static const char * GetPatchFileName(TMPQArchive * ha, const char * szFileName, char * szBuffer) diff --git a/src/StormLib.h b/src/StormLib.h index 901f943..b78f7ef 100644 --- a/src/StormLib.h +++ b/src/StormLib.h @@ -477,6 +477,8 @@ typedef enum _SFileInfoClass SFileInfoEncryptionKey, // File encryption key SFileInfoEncryptionKeyRaw, // Unfixed value of the file key SFileInfoCRC32, // CRC32 of the file + + SFileInfoInvalid = 0xFFF, // Invalid file info class } SFileInfoClass; //----------------------------------------------------------------------------- -- cgit v1.2.3