Archived
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.
This commit is contained in:
1 parent
f2f94fc6e7
commit
50ea36f283
1 file changed
+13
-6
+13
-6
@@ -518,15 +518,22 @@ int xs_profile_load(const std::string& path, std::vector<RadFileProfile>* out, i
|
|||||||
int64_t kept = 0;
|
int64_t kept = 0;
|
||||||
for (size_t l = 0; l < rows.size(); ++l) {
|
for (size_t l = 0; l < rows.size(); ++l) {
|
||||||
if (!rows[l].is_array()) continue;
|
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;
|
uint64_t sum = 0;
|
||||||
for (const auto& c : rows[l])
|
for (const auto& c : rows[l]) sum += c.get<uint64_t>();
|
||||||
if (c.is_number_unsigned() || c.is_number_integer())
|
|
||||||
sum += c.get<uint64_t>();
|
|
||||||
if (sum == 0) continue;
|
if (sum == 0) continue;
|
||||||
for (size_t e = 0; e < rows[l].size(); ++e) {
|
for (size_t e = 0; e < rows[l].size(); ++e) {
|
||||||
const auto& c = rows[l][e];
|
const uint64_t n = rows[l][e].get<uint64_t>();
|
||||||
if (!(c.is_number_unsigned() || c.is_number_integer())) continue;
|
|
||||||
const uint64_t n = c.get<uint64_t>();
|
|
||||||
if (n == 0) continue;
|
if (n == 0) continue;
|
||||||
RadFileProfile p{};
|
RadFileProfile p{};
|
||||||
p.layer = (int32_t)l;
|
p.layer = (int32_t)l;
|
||||||
|
|||||||
Reference in new issue
Block a user