+ Fixed possible stack overflow in HashStringJenkins

+ StormLib now creates a listfile even for empty archives to make sure it will be maintained at later point when files are added to it
+ Bug fixes in listfile loading
This commit is contained in:
unknown
2015-05-06 16:33:45 +02:00
parent abd17ec91e
commit 3cfa7f2a1a
11 changed files with 440 additions and 213 deletions

View File

@@ -377,6 +377,11 @@ int ConvertMpqHeaderToFormat4(
if(pHeader->dwBlockTablePos <= pHeader->dwHeaderSize || (pHeader->dwBlockTablePos & 0x80000000))
ha->dwFlags |= MPQ_FLAG_MALFORMED;
// Only low byte of sector size is really used
if(pHeader->wSectorSize & 0xFF00)
ha->dwFlags |= MPQ_FLAG_MALFORMED;
pHeader->wSectorSize = pHeader->wSectorSize & 0xFF;
// Fill the rest of the header
memset((LPBYTE)pHeader + MPQ_HEADER_SIZE_V1, 0, sizeof(TMPQHeader) - MPQ_HEADER_SIZE_V1);
pHeader->BlockTableSize64 = pHeader->dwBlockTableSize * sizeof(TMPQBlock);
@@ -568,6 +573,13 @@ int ConvertMpqHeaderToFormat4(
//-----------------------------------------------------------------------------
// Support for hash table
// Hash entry verification when the file table does not exist yet
bool IsValidHashEntry(TMPQArchive * ha, TMPQHash * pHash)
{
TFileEntry * pFileEntry = ha->pFileTable + pHash->dwBlockIndex;
return ((pHash->dwBlockIndex < ha->dwFileTableSize) && (pFileEntry->dwFlags & MPQ_FILE_EXISTS)) ? true : false;
}
// Hash entry verification when the file table does not exist yet
static bool IsValidHashEntry1(TMPQArchive * ha, TMPQHash * pHash, TMPQBlock * pBlockTable)
{
@@ -592,13 +604,6 @@ static bool IsValidHashEntry1(TMPQArchive * ha, TMPQHash * pHash, TMPQBlock * pB
return false;
}
// Hash entry verification when the file table does not exist yet
static bool IsValidHashEntry2(TMPQArchive * ha, TMPQHash * pHash)
{
TFileEntry * pFileEntry = ha->pFileTable + pHash->dwBlockIndex;
return ((pHash->dwBlockIndex < ha->dwFileTableSize) && (pFileEntry->dwFlags & MPQ_FILE_EXISTS)) ? true : false;
}
// Returns a hash table entry in the following order:
// 1) A hash table entry with the preferred locale
// 2) A hash table entry with the neutral locale
@@ -704,6 +709,7 @@ static TMPQHash * DefragmentHashTable(
if(dwNewTableSize < pHeader->dwHashTableSize)
{
pHashTable = STORM_REALLOC(TMPQHash, pHashTable, dwNewTableSize);
ha->pHeader->BlockTableSize64 = dwNewTableSize * sizeof(TMPQHash);
ha->pHeader->dwHashTableSize = dwNewTableSize;
}
@@ -814,10 +820,13 @@ static int BuildFileTableFromBlockTable(
if(ha->dwFileTableSize > ha->dwMaxFileCount)
{
ha->pFileTable = STORM_REALLOC(TFileEntry, ha->pFileTable, ha->dwMaxFileCount);
ha->pHeader->BlockTableSize64 = ha->dwMaxFileCount * sizeof(TMPQBlock);
ha->pHeader->dwBlockTableSize = ha->dwMaxFileCount;
ha->dwFileTableSize = ha->dwMaxFileCount;
}
// DumpFileTable(ha->pFileTable, ha->dwFileTableSize);
// Free the translation table
STORM_FREE(DefragmentTable);
}
@@ -2697,7 +2706,7 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize)
// Parse the old hash table and copy all entries to the new table
for(pHash = pOldHashTable; pHash < pHashTableEnd; pHash++)
{
if(IsValidHashEntry2(ha, pHash))
if(IsValidHashEntry(ha, pHash))
{
pFileEntry = ha->pFileTable + pHash->dwBlockIndex;
AllocateHashEntry(ha, pFileEntry, pHash->lcLocale);