From d9d0797b7f7e812f6e02b73151d55846e1b2e5f5 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 07:35:44 -0700 Subject: [PATCH] fix(wcp): cap info JSON string lengths at pack time A stray gigantic name/description/author field would inflate the info JSON past the 16MB unpack cap and make the pack unreadable via readInfo/unpackZone. Caps mirror the zone manifest limits. --- tools/editor/content_pack.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/editor/content_pack.cpp b/tools/editor/content_pack.cpp index 8fa1c56e..66985db7 100644 --- a/tools/editor/content_pack.cpp +++ b/tools/editor/content_pack.cpp @@ -39,13 +39,19 @@ bool ContentPacker::packZone(const std::string& outputDir, const std::string& ma return false; } - // Build info JSON + // Build info JSON. Cap string lengths so a stray gigantic field can't + // bloat the info JSON past the 16MB unpack cap (which would then make + // the pack unreadable via readInfo / unpackZone). + auto cap = [](std::string s, size_t n) { + if (s.size() > n) s.resize(n); + return s; + }; nlohmann::json infoObj; - infoObj["format"] = info.format; - infoObj["name"] = info.name; - infoObj["author"] = info.author; - infoObj["description"] = info.description; - infoObj["version"] = info.version; + infoObj["format"] = cap(info.format, 64); + infoObj["name"] = cap(info.name, 100); + infoObj["author"] = cap(info.author, 100); + infoObj["description"] = cap(info.description, 4096); + infoObj["version"] = cap(info.version, 32); infoObj["mapId"] = info.mapId; infoObj["fileCount"] = files.size(); nlohmann::json fileArr = nlohmann::json::array();