fix(dbc): range-check JSON DBC integer fields per-cell

val.get<uint32_t>() throws on negative or > UINT32_MAX. The
outer try-catch would then abort the entire JSON DBC load on a
single bad cell. Read as int64_t, clamp to [0, UINT32_MAX], and
zero out anything out of range — matches the per-field NaN scrub
applied to floats one branch up.
This commit is contained in:
Kelsi 2026-05-06 09:33:17 -07:00
parent 64b85ff9ff
commit 269e0a02ef

View file

@ -467,7 +467,12 @@ bool DBCFile::loadJSON(const std::vector<uint8_t>& jsonData) {
if (!std::isfinite(f)) f = 0.0f;
std::memcpy(&fields[col], &f, 4);
} else if (val.is_number_integer()) {
fields[col] = val.get<uint32_t>();
// Range-check: nlohmann throws on out-of-range get<uint32_t>
// (negative or > UINT32_MAX). Catching at the field level
// keeps a single bad cell from killing the whole DBC load.
int64_t raw = val.get<int64_t>();
if (raw < 0 || raw > 0xFFFFFFFFll) raw = 0;
fields[col] = static_cast<uint32_t>(raw);
}
}
}