From e9842c38cf9c55f682b2a411cea84ee59d69ec92 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Tue, 23 Dec 2014 15:04:35 +0100 Subject: + Adding files into MPQs that have BlockTableSize > HashTableSize is not allowed + Compacting MPQs that have BlockTableSize > HashTableSize is allowed --- src/SBaseFileTable.cpp | 7 +++++-- src/SFileAddFile.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index 2d6249f..68ad0d7 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -2629,7 +2629,6 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize, DWORD dwNewMaxF // The new hash table size must be greater or equal to the current hash table size assert(dwNewHashTableSize >= ha->pHeader->dwHashTableSize); - assert(dwNewMaxFileCount >= ha->dwFileTableSize); // The new hash table size must be a power of two assert((dwNewHashTableSize & (dwNewHashTableSize - 1)) == 0); @@ -2676,7 +2675,11 @@ int RebuildFileTable(TMPQArchive * ha, DWORD dwNewHashTableSize, DWORD dwNewMaxF if(ha->pHashTable != NULL) { pHash = AllocateHashEntry(ha, pFileEntry); - assert(pHash != NULL); + if(pHash == NULL) + { + nError = ERROR_DISK_FULL; + break; + } } // Move the file entry by one diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index 5997c1b..524fb50 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -725,6 +725,14 @@ bool WINAPI SFileCreateFile( nError = ERROR_INVALID_PARAMETER; } + // Check for MPQs that have invalid block table size + // Example: size of block table: 0x41, size of hash table: 0x40 + if(nError == ERROR_SUCCESS) + { + if(ha->dwFileTableSize > ha->dwMaxFileCount) + nError = ERROR_DISK_FULL; + } + // Initiate the add file operation if(nError == ERROR_SUCCESS) nError = SFileAddFile_Init(ha, szArchivedName, FileTime, dwFileSize, lcLocale, dwFlags, (TMPQFile **)phFile); -- cgit v1.2.3