Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions StormLib_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v141_xp</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
Expand All @@ -39,7 +39,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v141_xp</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/SBaseFileTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ DWORD ConvertMpqHeaderToFormat4(

// If version 1.0 is forced, then the format version is forced to be 1.0
// Reason: Storm.dll in Warcraft III ignores format version value
if((MapType == MapTypeWarcraft3) || (dwFlags & MPQ_OPEN_FORCE_MPQ_V1))
if((MapType == MapTypeStarcraft) || (MapType == MapTypeWarcraft3) || (dwFlags & MPQ_OPEN_FORCE_MPQ_V1))
wFormatVersion = MPQ_FORMAT_VERSION_1;

// Don't accept format 3 for Starcraft II maps
Expand All @@ -497,12 +497,21 @@ DWORD ConvertMpqHeaderToFormat4(
// Make sure that the MPQ Header is properly swapped
BSWAP_TMPQHEADER(pHeader, MPQ_FORMAT_VERSION_1);

// Check for blatantly wrong MPQ header by the hash table position
// Check for blatantly wrong MPQ header by the tables position
if(((ByteOffset + pHeader->dwHashTablePos) & 0xFFFFFFFF) > FileSize)
return ERROR_FAKE_MPQ_HEADER;
if(((ByteOffset + pHeader->dwBlockTablePos) & 0xFFFFFFFF) > FileSize)
return ERROR_FAKE_MPQ_HEADER;

// Check for blatantly wrong MPQ header by the tables size
if(MapType == MapTypeStarcraft)
{
if((pHeader->dwHashTableSize * sizeof(TMPQHash)) & 0xF0000000)
return ERROR_FAKE_MPQ_HEADER;
if((pHeader->dwBlockTableSize * sizeof(TMPQBlock)) & 0xF0000000)
return ERROR_FAKE_MPQ_HEADER;
}

// Check for malformed MPQ header version 1.0
if(pHeader->wFormatVersion != MPQ_FORMAT_VERSION_1 || pHeader->dwHeaderSize != MPQ_HEADER_SIZE_V1)
{
Expand Down
1 change: 1 addition & 0 deletions storm_dll/storm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ int main(int argc, char * argv[])

// Put Storm.dll to the current folder before running this
//printf("[*] Opening archive '%s' ...\n", szArchiveName);
__debugbreak();
if(StormOpenArchive(szArchiveName, 0, 0, &hMpq))
{
LPCSTR * FilesToOpen = DefFilesToOpen;
Expand Down
3 changes: 2 additions & 1 deletion test/StormTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4350,6 +4350,7 @@ static const TEST_INFO1 Test_OpenMpqs[] =
{_T("MPQ_2024_v1_300TK2.09p.w3x"), NULL, "e442e3d2e7d457b9ba544544013b791f", 32588}, // Fake MPQ User data, fake MPQ header at offset 0x200
{_T("MPQ_2025_v1_Legion_TD_11_2d-BETA_2_TeamOZE.w3x"), NULL, "08efaaa11cafe5e8921a6f112b2fa458", 626},
{_T("MPQ_2026_v1_The Art of Defense v4.11 G0A.w3x"), NULL, "892ec8421b34e35899624fc63b451327", 952}, // Some files have slash characters in their names
{_T("MPQ_2026_v1_BadTablesSize.scx"), NULL, "2dd05809bdcb466bbe35778086790caf", 3}, // Fake MPQ header at offset 0

// ASI plugins
{_T("mix-mpq/AHF04patch.mix"), NULL, "d3c6aac48bc12813ef5ce4ad113e58bf", 2891}, // MIX file
Expand Down Expand Up @@ -4483,7 +4484,7 @@ static void Test_PlayingSpace()
//-----------------------------------------------------------------------------
// Main

#define TEST_COMMAND_LINE
//#define TEST_COMMAND_LINE
#define TEST_LOCAL_LISTFILE
#define TEST_STREAM_OPERATIONS
#define TEST_MASTER_MIRROR
Expand Down
1 change: 1 addition & 0 deletions test/stormlib-test-001.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ TestReadingMpq (MPQ_2023_v1_Lusin2Rpg1.28.w3x) succeeded.
TestReadingMpq (MPQ_2024_v1_300TK2.09p.w3x) succeeded.
TestReadingMpq (MPQ_2025_v1_Legion_TD_11_2d-BETA_2_TeamOZE.w3x) succeeded.
TestReadingMpq (MPQ_2026_v1_The Art of Defense v4.11 G0A.w3x) succeeded.
TestReadingMpq (MPQ_2026_v1_BadTablesSize.scx) succeeded.
TestReadingMpq (mix-mpq/AHF04patch.mix) succeeded.
TestReadingMpq (mix-mpq/hs0.1.asi) succeeded.
TestReadingMpq (mix-mpq/hs0.8.asi) succeeded.
Expand Down
Loading