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.
This commit is contained in:
Kelsi 2026-05-06 07:35:44 -07:00
parent efd0a6de29
commit d9d0797b7f

View file

@ -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();