Fix huge memory allocation when decoding PNG, which can end up with std::bad_alloc (#43)

This commit is contained in:
emmcbd
2018-08-08 16:45:57 +02:00
committed by Romain Guy
parent bb75923b79
commit de1743c572

View File

@@ -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<png_bytep[]> rowPointers(new png_bytep[height]);
for (size_t y = 0 ; y < height ; y++) {
rowPointers[y] = &imageData[y * rowBytes];