fix(wcp): cap per-file size at pack to match unpack limit (256MB)

Pack previously accepted any file < 4GB and wrote it raw. Unpack
caps at 256MB and rejects the whole archive on overflow — so a
huge file in the source dir would silently produce an unpackable
WCP. Cap at pack and skip the body (size=0 entry) so the rest of
the pack remains usable.
This commit is contained in:
Kelsi 2026-05-06 09:35:49 -07:00
parent d85073241e
commit 377cfb32d3

View file

@ -93,8 +93,13 @@ bool ContentPacker::packZone(const std::string& outputDir, const std::string& ma
std::ifstream fin(full, std::ios::binary | std::ios::ate);
std::streamsize sz = fin.tellg();
if (sz < 0 || static_cast<uint64_t>(sz) > 0xFFFFFFFFull) {
LOG_ERROR("WCP skipped file (size out of range): ", rel);
// Cap at the unpack-side per-file limit (256MB) so we never write
// a pack the loader will reject as a whole. Files that big are
// almost certainly an authoring mistake — log + skip the body
// instead of producing an unpackable archive.
constexpr uint64_t kMaxFileBytes = 256ull * 1024 * 1024;
if (sz < 0 || static_cast<uint64_t>(sz) > kMaxFileBytes) {
LOG_ERROR("WCP skipped file (size ", sz, " > 256MB cap): ", rel);
uint32_t zero = 0;
out.write(reinterpret_cast<const char*>(&zero), 4);
continue;