fix(whm): reject load on overlong per-chunk alphaSize

Same load-desync pattern as elsewhere — alphaSize > 65536 silently
skipped the read but the actual alpha bytes were still on disk, so
the next chunk's baseHeight float read would parse alpha bytes.
Now rejects the load with LOG_ERROR.
This commit is contained in:
Kelsi 2026-05-06 09:31:36 -07:00
parent 9facea14a7
commit 64b85ff9ff

View file

@ -58,9 +58,17 @@ bool WoweeTerrainLoader::loadHeightmap(const std::string& whmPath, ADTTerrain& t
if (!std::isfinite(h)) h = 0.0f;
}
// Read alpha map data (may not be present in older WHM files)
// Read alpha map data (may not be present in older WHM files).
// Reject overlong alphaSize to keep the per-chunk block alignment —
// skipping a 100MB alpha block would leave the next chunk's
// baseHeight read parsing alpha bytes as floats.
uint32_t alphaSize = 0;
if (f.read(reinterpret_cast<char*>(&alphaSize), 4) && alphaSize > 0 && alphaSize <= 65536) {
if (f.read(reinterpret_cast<char*>(&alphaSize), 4) && alphaSize > 0) {
if (alphaSize > 65536) {
LOG_ERROR("WHM chunk ", ci, " alphaSize rejected (",
alphaSize, "): ", whmPath);
return false;
}
chunk.alphaMap.resize(alphaSize);
f.read(reinterpret_cast<char*>(chunk.alphaMap.data()), alphaSize);
}