From d3a85776f805c839d36647493e68308d2ffc6fb9 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 06:27:04 -0700 Subject: [PATCH] fix(content-pack): packZone truncates path length + skips files >4GB Two write-side guards mirroring the unpack-side ones: - Path length truncated to 1KB (matches unpack cap; long paths would silently wrap u16 and corrupt the pack) - Files >4GB on disk skipped with a zero-length entry rather than silently producing a truncated dataSize that overflows uint32 --- tools/editor/content_pack.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/editor/content_pack.cpp b/tools/editor/content_pack.cpp index 688fd1c6..f7f91a16 100644 --- a/tools/editor/content_pack.cpp +++ b/tools/editor/content_pack.cpp @@ -74,12 +74,21 @@ bool ContentPacker::packZone(const std::string& outputDir, const std::string& ma // File table + data for (const auto& [rel, full] : files) { - uint16_t pathLen = static_cast(rel.size()); + // Truncate path length to fit u16; matches the unpack-side cap. + // Also skip files whose disk size doesn't fit in uint32 (4GB). + uint16_t pathLen = static_cast(std::min(rel.size(), 1024)); out.write(reinterpret_cast(&pathLen), 2); out.write(rel.data(), pathLen); std::ifstream fin(full, std::ios::binary | std::ios::ate); - uint32_t dataSize = static_cast(fin.tellg()); + std::streamsize sz = fin.tellg(); + if (sz < 0 || static_cast(sz) > 0xFFFFFFFFull) { + LOG_ERROR("WCP skipped file (size out of range): ", rel); + uint32_t zero = 0; + out.write(reinterpret_cast(&zero), 4); + continue; + } + uint32_t dataSize = static_cast(sz); fin.seekg(0); out.write(reinterpret_cast(&dataSize), 4);