mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-29 18:32:36 +00:00
Make BA2 extension hash calculation safer (#7784)
This commit is contained in:
parent
c45c2355ae
commit
84ab7afd44
@ -177,7 +177,7 @@ namespace Bsa
|
||||
return std::nullopt; // folder not found
|
||||
|
||||
uint32_t fileHash = generateHash(fileName);
|
||||
uint32_t extHash = *reinterpret_cast<const uint32_t*>(ext.data() + 1);
|
||||
uint32_t extHash = generateExtensionHash(ext);
|
||||
auto iter = it->second.find({ fileHash, extHash });
|
||||
if (iter == it->second.end())
|
||||
return std::nullopt; // file not found
|
||||
|
@ -46,4 +46,12 @@ namespace Bsa
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t generateExtensionHash(std::string_view extension)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for (size_t i = 0; i < 4 && i < extension.size() - 1; i++)
|
||||
result |= static_cast<uint8_t>(extension[i + 1]) << (8 * i);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Bsa
|
||||
|
@ -7,6 +7,7 @@
|
||||
namespace Bsa
|
||||
{
|
||||
uint32_t generateHash(const std::string& name);
|
||||
uint32_t generateExtensionHash(std::string_view extension);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -172,7 +172,7 @@ namespace Bsa
|
||||
return FileRecord(); // folder not found, return default which has offset of sInvalidOffset
|
||||
|
||||
uint32_t fileHash = generateHash(fileName);
|
||||
uint32_t extHash = *reinterpret_cast<const uint32_t*>(ext.data() + 1);
|
||||
uint32_t extHash = generateExtensionHash(ext);
|
||||
auto iter = it->second.find({ fileHash, extHash });
|
||||
if (iter == it->second.end())
|
||||
return FileRecord(); // file not found, return default which has offset of sInvalidOffset
|
||||
|
Loading…
x
Reference in New Issue
Block a user