From ca3cabf0670f1d313412f6eb0db7dad3a5e6be56 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 11 Aug 2022 21:22:46 +0200 Subject: Fixed null-terminated extraction --- ArchiveEx/Archive.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArchiveEx/Archive.cpp b/ArchiveEx/Archive.cpp index 8ca7b71..0a99982 100644 --- a/ArchiveEx/Archive.cpp +++ b/ArchiveEx/Archive.cpp @@ -78,14 +78,14 @@ Archive::Expand(const int index, std::uint8_t*& buffer, const bool null_terminat const std::size_t length = std::fread(compressed.data(), 1, entry.compressed_size, file.get()); if (entry.compressed_size != length) return -1; - uLongf output_length = entry.original_size + static_cast(null_terminated); - auto uncompressed = std::make_unique(output_length); + uLongf output_length = entry.original_size; + auto uncompressed = std::make_unique(output_length + null_terminated); err = uncompress(uncompressed.get(), &output_length, compressed.data(), entry.compressed_size); if (Z_OK != err) return -1; buffer = uncompressed.release(); if (null_terminated) - buffer[output_length - 1] = 0; + buffer[output_length] = 0; return output_length; } -- cgit v1.1