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