From 3b1d6a7e627b29df6c3eb1ad60ab0c9a2ecc9e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Mocquillon?= Date: Fri, 18 Aug 2023 18:47:30 +0200 Subject: [PATCH] Use the right size --- components/bsa/ba2gnrlfile.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/components/bsa/ba2gnrlfile.cpp b/components/bsa/ba2gnrlfile.cpp index 0e4cabd075..bdb0457034 100644 --- a/components/bsa/ba2gnrlfile.cpp +++ b/components/bsa/ba2gnrlfile.cpp @@ -202,23 +202,21 @@ namespace Bsa Files::IStreamPtr BA2GNRLFile::getFile(const FileRecord& fileRecord) { - Files::IStreamPtr streamPtr - = Files::openConstrainedFileStream(mFilepath, fileRecord.offset, fileRecord.packedSize); - std::istream* fileStream = streamPtr.get(); - uint32_t uncompressedSize = fileRecord.size; - auto memoryStreamPtr = std::make_unique(uncompressedSize); - if (fileRecord.packedSize != 0) + const uint32_t inputSize = fileRecord.packedSize ? fileRecord.packedSize : fileRecord.size; + Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilepath, fileRecord.offset, inputSize); + auto memoryStreamPtr = std::make_unique(fileRecord.size); + if (fileRecord.packedSize) { boost::iostreams::filtering_streambuf inputStreamBuf; inputStreamBuf.push(boost::iostreams::zlib_decompressor()); - inputStreamBuf.push(*fileStream); + inputStreamBuf.push(*streamPtr); - boost::iostreams::basic_array_sink sr(memoryStreamPtr->getRawData(), uncompressedSize); + boost::iostreams::basic_array_sink sr(memoryStreamPtr->getRawData(), fileRecord.size); boost::iostreams::copy(inputStreamBuf, sr); } else { - fileStream->read(memoryStreamPtr->getRawData(), fileRecord.size); + streamPtr->read(memoryStreamPtr->getRawData(), fileRecord.size); } return std::make_unique>(std::move(memoryStreamPtr)); }