mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
VpkLib: move header check to dir construction and flag error on failure
Moved the construction as otherwise we would iterate over potentially bad or incompatible data.
This commit is contained in:
parent
6f0fdd56ce
commit
8ff1404c4d
@ -569,14 +569,6 @@ void CPackedStoreBuilder::UnpackStore(const VPKDir_t& vpkDir, const char* worksp
|
||||
workspacePath.AppendSlash();
|
||||
workspacePath.FixSlashes('/');
|
||||
|
||||
if (vpkDir.m_Header.m_nHeaderMarker != VPK_HEADER_MARKER ||
|
||||
vpkDir.m_Header.m_nMajorVersion != VPK_MAJOR_VERSION ||
|
||||
vpkDir.m_Header.m_nMinorVersion != VPK_MINOR_VERSION)
|
||||
{
|
||||
Error(eDLL_T::FS, NO_ERROR, "Unsupported VPK directory file (invalid header criteria)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<uint8_t[]> pDestBuffer(new uint8_t[ENTRY_MAX_LEN]);
|
||||
std::unique_ptr<uint8_t[]> pSourceBuffer(new uint8_t[ENTRY_MAX_LEN]);
|
||||
|
||||
@ -927,13 +919,28 @@ void VPKDir_t::Init(const CUtlString& dirFilePath)
|
||||
FileHandle_t hDirFile = FileSystem()->Open(dirFilePath.Get(), "rb", "GAME");
|
||||
if (!hDirFile)
|
||||
{
|
||||
Error(eDLL_T::FS, NO_ERROR, "%s - Unable to open '%s' (insufficient rights?)\n", __FUNCTION__, dirFilePath.Get());
|
||||
Error(eDLL_T::FS, NO_ERROR, "Unable to open '%s' (insufficient rights?)\n", dirFilePath.Get());
|
||||
m_bInitFailed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystem()->Read(&m_Header.m_nHeaderMarker, sizeof(uint32_t), hDirFile);
|
||||
FileSystem()->Read(&m_Header.m_nMajorVersion, sizeof(uint16_t), hDirFile); //
|
||||
FileSystem()->Read(&m_Header.m_nMinorVersion, sizeof(uint16_t), hDirFile); //
|
||||
|
||||
// Make sure this is an actual directory tree file, and one we support.
|
||||
if (m_Header.m_nHeaderMarker != VPK_HEADER_MARKER ||
|
||||
m_Header.m_nMajorVersion != VPK_MAJOR_VERSION ||
|
||||
m_Header.m_nMinorVersion != VPK_MINOR_VERSION)
|
||||
{
|
||||
Error(eDLL_T::FS, NO_ERROR, "Unsupported VPK directory file (invalid header criteria)\n");
|
||||
FileSystem()->Close(hDirFile);
|
||||
m_bInitFailed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystem()->Read(&m_Header.m_nDirectorySize, sizeof(uint32_t), hDirFile); //
|
||||
FileSystem()->Read(&m_Header.m_nSignatureSize, sizeof(uint32_t), hDirFile); //
|
||||
|
||||
@ -948,6 +955,7 @@ void VPKDir_t::Init(const CUtlString& dirFilePath)
|
||||
}
|
||||
|
||||
FileSystem()->Close(hDirFile);
|
||||
m_bInitFailed = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -145,6 +145,7 @@ struct VPKDir_t
|
||||
// This set only contains packfile indices used
|
||||
// by the directory tree, notated as pak000_xxx.
|
||||
std::set<uint16_t> m_PakFileIndices;
|
||||
bool m_bInitFailed;
|
||||
|
||||
class CTreeBuilder
|
||||
{
|
||||
@ -163,11 +164,13 @@ struct VPKDir_t
|
||||
{
|
||||
m_Header.m_nHeaderMarker = VPK_HEADER_MARKER; m_Header.m_nMajorVersion = VPK_MAJOR_VERSION;
|
||||
m_Header.m_nMinorVersion = VPK_MINOR_VERSION; m_Header.m_nDirectorySize = NULL, m_Header.m_nSignatureSize = NULL;
|
||||
m_bInitFailed = false;
|
||||
};
|
||||
VPKDir_t(const CUtlString& svDirectoryFile);
|
||||
VPKDir_t(const CUtlString& svDirectoryFile, bool bSanitizeName);
|
||||
|
||||
void Init(const CUtlString& svPath);
|
||||
inline bool Failed() const { return m_bInitFailed; }
|
||||
|
||||
CUtlString StripLocalePrefix(const CUtlString& svDirectoryFile) const;
|
||||
CUtlString GetPackFileNameForIndex(uint16_t iPackFileIndex) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user