mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 17:43:51 +00:00
fix(validate): require minimum body bytes when checking format magic
A 4-byte file with just the right magic and no body would pass the previous magic-only check but fail any actual loader. Require at least 8 bytes (magic + 1 field) for a file to count as 'valid' in the score.
This commit is contained in:
parent
8fb7690ea1
commit
303eeb9107
1 changed files with 10 additions and 0 deletions
|
|
@ -294,6 +294,13 @@ bool ContentPacker::readInfo(const std::string& wcpPath, ContentPackInfo& info)
|
|||
static bool checkMagic(const std::string& path, uint32_t expectedMagic) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (!f) return false;
|
||||
// Require minimum body bytes after the 4-byte magic. A 4-byte file
|
||||
// with only the right magic is not a valid asset; the format-specific
|
||||
// load routines would reject it but the magic-only check would pass.
|
||||
f.seekg(0, std::ios::end);
|
||||
auto fileSize = f.tellg();
|
||||
if (fileSize < 8) return false;
|
||||
f.seekg(0, std::ios::beg);
|
||||
uint32_t magic = 0;
|
||||
f.read(reinterpret_cast<char*>(&magic), 4);
|
||||
return magic == expectedMagic;
|
||||
|
|
@ -304,6 +311,9 @@ static bool checkAnyMagic(const std::string& path,
|
|||
std::initializer_list<uint32_t> expected) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (!f) return false;
|
||||
f.seekg(0, std::ios::end);
|
||||
if (f.tellg() < 8) return false;
|
||||
f.seekg(0, std::ios::beg);
|
||||
uint32_t magic = 0;
|
||||
f.read(reinterpret_cast<char*>(&magic), 4);
|
||||
for (uint32_t e : expected) if (magic == e) return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue