mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 09:33:51 +00:00
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
This commit is contained in:
parent
5019e21787
commit
d3a85776f8
1 changed files with 11 additions and 2 deletions
|
|
@ -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<uint16_t>(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<uint16_t>(std::min<size_t>(rel.size(), 1024));
|
||||
out.write(reinterpret_cast<const char*>(&pathLen), 2);
|
||||
out.write(rel.data(), pathLen);
|
||||
|
||||
std::ifstream fin(full, std::ios::binary | std::ios::ate);
|
||||
uint32_t dataSize = static_cast<uint32_t>(fin.tellg());
|
||||
std::streamsize sz = fin.tellg();
|
||||
if (sz < 0 || static_cast<uint64_t>(sz) > 0xFFFFFFFFull) {
|
||||
LOG_ERROR("WCP skipped file (size out of range): ", rel);
|
||||
uint32_t zero = 0;
|
||||
out.write(reinterpret_cast<const char*>(&zero), 4);
|
||||
continue;
|
||||
}
|
||||
uint32_t dataSize = static_cast<uint32_t>(sz);
|
||||
fin.seekg(0);
|
||||
out.write(reinterpret_cast<const char*>(&dataSize), 4);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue