From 50ea36f283b18357d4bd57c2ac38ffd2ab61c530 Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 17:20:39 +0000 Subject: [PATCH] place: a profile's counts must be unsigned to steer anything The expert-profile loader summed whatever JSON numbers it found and the planner's arithmetic read them as unsigned. A negative count read as uint64_t wraps to a value near 2^64, which reads back as a ~100% share: whoever wrote the file could point the pinning at any expert they named. Under the old JSON library a negative threw its way out of here; the facade's arithmetic read does not, so the file is now refused by name. Every entry of a decode row must now be a non-negative JSON integer; the offender's layer and expert are printed, and RAD_E_INVAL comes back before a single wrapped share reaches the planner. --- core/place/xstats.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/place/xstats.cpp b/core/place/xstats.cpp index 6fffb654..acd04b8f 100644 --- a/core/place/xstats.cpp +++ b/core/place/xstats.cpp @@ -518,15 +518,22 @@ int xs_profile_load(const std::string& path, std::vector* out, i int64_t kept = 0; for (size_t l = 0; l < rows.size(); ++l) { if (!rows[l].is_array()) continue; + /* Counts are unsigned. The facade's arithmetic read casts -- a negative read as + * uint64_t wraps to 2^64-ish, and a wrapped count reads as a ~100% share, steering the + * planner's pinning at whatever the file's author named. Under the old JSON library a + * negative threw its way out of here; refuse the file by name instead. */ + for (size_t e = 0; e < rows[l].size(); ++e) + if (!rows[l][e].is_number_unsigned()) { + RAD_ERR("--expert-profile: %s carries a negative or fractional count at decode " + "layer %zu expert %zu; the format's counts are unsigned", + path.c_str(), l, e); + return RAD_E_INVAL; + } uint64_t sum = 0; - for (const auto& c : rows[l]) - if (c.is_number_unsigned() || c.is_number_integer()) - sum += c.get(); + for (const auto& c : rows[l]) sum += c.get(); if (sum == 0) continue; for (size_t e = 0; e < rows[l].size(); ++e) { - const auto& c = rows[l][e]; - if (!(c.is_number_unsigned() || c.is_number_integer())) continue; - const uint64_t n = c.get(); + const uint64_t n = rows[l][e].get(); if (n == 0) continue; RadFileProfile p{}; p.layer = (int32_t)l;