MCPcopy Create free account
hub / github.com/diasurgical/devilution / IsValidMpqUserData

Function IsValidMpqUserData

3rdParty/StormLib/src/SFileOpenArchive.cpp:44–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44static TMPQUserData * IsValidMpqUserData(ULONGLONG ByteOffset, ULONGLONG FileSize, void * pvUserData)
45{
46 TMPQUserData * pUserData;
47
48 // BSWAP the source data and copy them to our buffer
49 BSWAP_ARRAY32_UNSIGNED(&pvUserData, sizeof(TMPQUserData));
50 pUserData = (TMPQUserData *)pvUserData;
51
52 // Check the sizes
53 if(pUserData->cbUserDataHeader <= pUserData->cbUserDataSize && pUserData->cbUserDataSize <= pUserData->dwHeaderOffs)
54 {
55 // Move to the position given by the userdata
56 ByteOffset += pUserData->dwHeaderOffs;
57
58 // The MPQ header should be within range of the file size
59 if((ByteOffset + MPQ_HEADER_SIZE_V1) < FileSize)
60 {
61 // Note: We should verify if there is the MPQ header.
62 // However, the header could be at any position below that
63 // that is multiplier of 0x200
64 return (TMPQUserData *)pvUserData;
65 }
66 }
67
68 return NULL;
69}
70
71// This function gets the right positions of the hash table and the block table.
72static int VerifyMpqTablePositions(TMPQArchive * ha, ULONGLONG FileSize)

Callers 1

SFileOpenArchiveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected