From d41725e3254eb4fcb52e1e2ccd8ececb98d6bc16 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 3 Mar 2025 01:47:34 -0600 Subject: [PATCH] [Hotfix] Fix sigabort crash from invalid JSON --- zone/zone_save_state.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/zone/zone_save_state.cpp b/zone/zone_save_state.cpp index 0c75aa304..ecc50fff9 100644 --- a/zone/zone_save_state.cpp +++ b/zone/zone_save_state.cpp @@ -45,10 +45,22 @@ struct LootStateData { } }; +inline bool IsValidJson(const std::string& json) { + rapidjson::Document doc; + rapidjson::ParseResult result = doc.Parse(json.c_str()); + + return result; +} + inline void LoadLootStateData(Zone *zone, NPC *npc, const std::string &loot_data) { LootStateData l{}; + if (!IsValidJson(loot_data)) { + LogZoneState("Invalid JSON data for NPC [{}]", npc->GetNPCTypeID()); + return; + } + try { std::stringstream ss; { @@ -166,6 +178,11 @@ inline std::string GetLootSerialized(Corpse *c) inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables) { + if (!IsValidJson(entity_variables)) { + LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID()); + return; + } + std::map deserialized_map; try { std::istringstream is(entity_variables); @@ -186,6 +203,11 @@ inline void LoadNPCEntityVariables(NPC *n, const std::string &entity_variables) inline void LoadNPCBuffs(NPC *n, const std::string &buffs) { + if (!IsValidJson(buffs)) { + LogZoneState("Invalid JSON data for NPC [{}]", n->GetNPCTypeID()); + return; + } + std::vector valid_buffs; try { std::istringstream is(buffs);