fix(npc): range-check waypoint waitTimeMs per-cell on load

Same per-cell range-check pattern as the JSON DBC fix: if a
waypoint's waitTime field is negative or > UINT32_MAX, the
.get<uint32_t> throws json::type_error and the outer try-catch
aborts the entire NPC file load on a single bad waypoint. Read
as int64, clamp to [0, 600000ms = 10-min cap].
This commit is contained in:
Kelsi 2026-05-06 09:41:11 -07:00
parent f76aebc4b9
commit 7552880ca1

View file

@ -233,12 +233,16 @@ bool NpcSpawner::loadFromFile(const std::string& path) {
if (!std::isfinite(pp.position.x) || !std::isfinite(pp.position.y) ||
!std::isfinite(pp.position.z))
continue;
pp.waitTimeMs = pt[3].get<uint32_t>();
// Cap wait time at 10 minutes to keep AzerothCore
// happy and prevent obvious data-entry typos that
// would produce a creature that effectively never
// moves (e.g. 24h = 86400000).
if (pp.waitTimeMs > 600000) pp.waitTimeMs = 600000;
// Read waitTime as int64 then clamp to uint32_t range.
// pt[3].get<uint32_t> would throw json::type_error on
// a negative or out-of-range integer and abort the
// whole NPC file load on a single bad waypoint.
int64_t rawWait = pt[3].is_number_float()
? static_cast<int64_t>(pt[3].get<double>())
: pt[3].get<int64_t>();
if (rawWait < 0) rawWait = 0;
if (rawWait > 600000) rawWait = 600000; // 10-min cap
pp.waitTimeMs = static_cast<uint32_t>(rawWait);
s.patrolPath.push_back(pp);
}
}