Fix huge memory allocation when decoding PNG, which can end up with std::bad_alloc (#43)
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user