From 4a0c4ec6098bbff1491c13778ef15fd1f9e9683a Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 9 Jan 2016 16:02:54 +0100 Subject: [PATCH] Fix stack overflow in zlib decompress routine. --- src/Utils/Compression.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Utils/Compression.cpp b/src/Utils/Compression.cpp index e64e9442..4b43b53d 100644 --- a/src/Utils/Compression.cpp +++ b/src/Utils/Compression.cpp @@ -50,11 +50,11 @@ namespace Utils if (inflateInit(&stream) != Z_OK) { - return buffer; + return ""; } int ret = 0; - uint8_t dest[CHUNK] = { 0 }; + uint8_t* dest = new uint8_t[CHUNK]; const char* dataPtr = data.data(); do @@ -71,6 +71,8 @@ namespace Utils if (ret == Z_STREAM_ERROR) { inflateEnd(&stream); + delete[] dest; + return ""; } buffer.append(reinterpret_cast(dest), CHUNK - stream.avail_out); @@ -81,6 +83,8 @@ namespace Utils inflateEnd(&stream); + delete[] dest; + return buffer; } };