aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2023-12-21 22:37:46 +0100
committerGitHub <noreply@github.com>2023-12-21 22:37:46 +0100
commit61b6665433e8de0e4be68e69ddfb0128421d4057 (patch)
treedba51804af1606b558d4e2eb74b7428f6171e932 /src
parentaaa011852dcbbf92cc2475720291198d6f5597ca (diff)
parent2b50c079cb28d5becb347c54777edca6c9771ea3 (diff)
Merge pull request #313 from ladislav-zezula/LZ_TabsToSpaces
Fixed https://github.com/ladislav-zezula/StormLib/issues/311
Diffstat (limited to 'src')
-rw-r--r--src/SFileGetFileInfo.cpp14
-rw-r--r--src/SFileOpenFileEx.cpp13
-rw-r--r--src/StormLib.h2
3 files changed, 22 insertions, 7 deletions
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;
//-----------------------------------------------------------------------------