From 2ef81277a8c7ad0c65d1c081591b7505449c623e Mon Sep 17 00:00:00 2001 From: ephphatha Date: Sun, 17 Apr 2022 13:18:37 +1000 Subject: [PATCH] Ensure working buffers are zero-initialised for PKWareLib explode() and implode() both have comments saying they expect the buffers to be zero-init, however new[] default initialises arrays which for char[] leaves them in an implementation defined state. On MSVC the memory is unitialised. To be safe use std::make_unique(size_t) as this value-initialises each element of the array. --- Source/encrypt.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/encrypt.cpp b/Source/encrypt.cpp index 3c167ea34..87a00a9b0 100644 --- a/Source/encrypt.cpp +++ b/Source/encrypt.cpp @@ -103,7 +103,7 @@ uint32_t Hash(const char *s, int type) uint32_t PkwareCompress(byte *srcData, uint32_t size) { - std::unique_ptr ptr { new char[CMP_BUFFER_SIZE] }; + std::unique_ptr ptr = std::make_unique(CMP_BUFFER_SIZE); unsigned destSize = 2 * size; if (destSize < 2 * 4096) @@ -132,11 +132,10 @@ uint32_t PkwareCompress(byte *srcData, uint32_t size) void PkwareDecompress(byte *inBuff, int recvSize, int maxBytes) { - TDataInfo info; - - std::unique_ptr ptr { new char[CMP_BUFFER_SIZE] }; + std::unique_ptr ptr = std::make_unique(CMP_BUFFER_SIZE); std::unique_ptr outBuff { new byte[maxBytes] }; + TDataInfo info; info.srcData = inBuff; info.srcOffset = 0; info.destData = outBuff.get();