From de1743c572fd8ea7dbe12dc72305bdbffb45e778 Mon Sep 17 00:00:00 2001 From: emmcbd <42184090+emmcbd@users.noreply.github.com> Date: Wed, 8 Aug 2018 16:45:57 +0200 Subject: [PATCH] Fix huge memory allocation when decoding PNG, which can end up with std::bad_alloc (#43) --- libs/imageio/src/ImageDecoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/imageio/src/ImageDecoder.cpp b/libs/imageio/src/ImageDecoder.cpp index c8c1393f6e..5b6a8d08d4 100644 --- a/libs/imageio/src/ImageDecoder.cpp +++ b/libs/imageio/src/ImageDecoder.cpp @@ -290,7 +290,7 @@ Image PNGDecoder::decode() { uint32_t height = png_get_image_height(mPNG, mInfo); size_t rowBytes = png_get_rowbytes(mPNG, mInfo); - imageData.reset(new uint8_t[width * height * rowBytes]); + imageData.reset(new uint8_t[height * rowBytes]); std::unique_ptr rowPointers(new png_bytep[height]); for (size_t y = 0 ; y < height ; y++) { rowPointers[y] = &imageData[y * rowBytes];