mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-09 18:43:51 +00:00
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:
parent
efd0a6de29
commit
d9d0797b7f
1 changed files with 12 additions and 6 deletions
|
|
@ -39,13 +39,19 @@ bool ContentPacker::packZone(const std::string& outputDir, const std::string& ma
|
||||||
return false;
|
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;
|
nlohmann::json infoObj;
|
||||||
infoObj["format"] = info.format;
|
infoObj["format"] = cap(info.format, 64);
|
||||||
infoObj["name"] = info.name;
|
infoObj["name"] = cap(info.name, 100);
|
||||||
infoObj["author"] = info.author;
|
infoObj["author"] = cap(info.author, 100);
|
||||||
infoObj["description"] = info.description;
|
infoObj["description"] = cap(info.description, 4096);
|
||||||
infoObj["version"] = info.version;
|
infoObj["version"] = cap(info.version, 32);
|
||||||
infoObj["mapId"] = info.mapId;
|
infoObj["mapId"] = info.mapId;
|
||||||
infoObj["fileCount"] = files.size();
|
infoObj["fileCount"] = files.size();
|
||||||
nlohmann::json fileArr = nlohmann::json::array();
|
nlohmann::json fileArr = nlohmann::json::array();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue