From c4c8d9e7ed175f974e710fea5af12fde75b0f6b1 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 05:56:11 -0700 Subject: [PATCH] fix(editor): quest objective load clamps type, count, and per-quest size Three guards on quest objective loading from JSON: - type out of QuestObjectiveType range (0..5) -> defaults to 0 (Kill) - targetCount of 0 -> 1 (no-op objectives are nonsense) - targetCount > 1000 -> 1000 (typo guard, biggest legit WoW quest is ~100) - >10 objectives per quest -> dropped (matches SQL slot capacity, also bounds per-quest memory) --- tools/editor/quest_editor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/editor/quest_editor.cpp b/tools/editor/quest_editor.cpp index 7e419cec..94041b70 100644 --- a/tools/editor/quest_editor.cpp +++ b/tools/editor/quest_editor.cpp @@ -102,10 +102,19 @@ bool QuestEditor::loadFromFile(const std::string& path) { if (jq.contains("objectives") && jq["objectives"].is_array()) { for (const auto& jo : jq["objectives"]) { QuestObjective obj; - obj.type = static_cast(jo.value("type", 0)); + int t = jo.value("type", 0); + // Clamp to known QuestObjectiveType range to avoid + // garbage enum values from edited JSON. + if (t < 0 || t > 5) t = 0; + obj.type = static_cast(t); obj.description = jo.value("desc", ""); obj.targetName = jo.value("target", ""); obj.targetCount = jo.value("count", 1u); + if (obj.targetCount == 0) obj.targetCount = 1; + if (obj.targetCount > 1000) obj.targetCount = 1000; + // Cap stored objectives to 10 (matches SQL slot capacity) + // — also bounds the per-quest memory. + if (q.objectives.size() >= 10) break; q.objectives.push_back(obj); } }