fix(woc): reject corrupted triCount + clamp out-of-range tile coords

Header sanity bounds for WOC matching the WOM/WoB ones. A whole-tile
collision mesh maxes at ~32K terrain tris + a few thousand building
overlay tris; triCount > 2M is corrupted and would OOM. Tile coords
are 0..63 in WoW; clamp to 32 with warning when bogus.
This commit is contained in:
Kelsi 2026-05-06 05:44:37 -07:00
parent 90289ba48b
commit a7d62d1af9

View file

@ -195,6 +195,20 @@ WoweeCollision WoweeCollisionBuilder::load(const std::string& path) {
f.read(reinterpret_cast<char*>(&col.tileY), 4);
f.read(reinterpret_cast<char*>(&col.bounds.min), 12);
f.read(reinterpret_cast<char*>(&col.bounds.max), 12);
// A whole-tile collision mesh tops out at ~256*128 = 32K terrain triangles
// plus building overlays. >2M is corrupted and would OOM us.
if (triCount > 2'000'000) {
LOG_ERROR("WOC triCount rejected (", triCount, "): ", path);
return WoweeCollision{};
}
// Tile coords are valid 0..63 in WoW; cap higher values that suggest
// a corrupted file rather than letting them propagate.
if (col.tileX > 63 || col.tileY > 63) {
LOG_WARNING("WOC tile coord out of range (", col.tileX, ",", col.tileY,
") — clamping");
if (col.tileX > 63) col.tileX = 32;
if (col.tileY > 63) col.tileY = 32;
}
col.triangles.reserve(triCount);
auto fixVec = [](glm::vec3& v) {