From bae2b9931cae81a9eface9214e6b83e0bc2ef726 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 7 May 2020 22:28:55 +1000 Subject: [PATCH] Fix PNG images which had some garbage data in IDAT chunk after compressed image data not loading (Thanks goodly) --- src/Bitmap.c | 14 +++++++++----- src/Errors.h | 2 +- src/Logger.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Bitmap.c b/src/Bitmap.c index efe19fc70..5efaf26fd 100644 --- a/src/Bitmap.c +++ b/src/Bitmap.c @@ -507,13 +507,17 @@ cc_result Png_Decode(Bitmap* bmp, struct Stream* stream) { rowExpander(bmp->Width, palette, &scanline[1], Bitmap_GetRow(bmp, curY)); } } + + if (curY == bmp->Height) { + if (!BitmapCol_A(trnsCol)) ComputeTransparency(bmp, trnsCol); + return 0; + } } break; - case PNG_FourCC('I','E','N','D'): { - if (dataSize) return PNG_ERR_INVALID_END_SIZE; - if (!BitmapCol_A(trnsCol)) ComputeTransparency(bmp, trnsCol); - return bmp->Scan0 ? 0 : PNG_ERR_NO_DATA; - } break; + case PNG_FourCC('I','E','N','D'): + /* Reading all image data should be handled by above if in the IDAT chunk */ + /* If we reached here, it means not all of the image data was read */ + return PNG_ERR_REACHED_IEND; default: if ((res = stream->Skip(stream, dataSize))) return res; diff --git a/src/Errors.h b/src/Errors.h index e7241756d..10dc348c9 100644 --- a/src/Errors.h +++ b/src/Errors.h @@ -27,7 +27,7 @@ enum ERRORS_ALL { /* PNG image decoding errors */ PNG_ERR_INVALID_SIG, PNG_ERR_INVALID_HDR_SIZE, PNG_ERR_TOO_WIDE, PNG_ERR_TOO_TALL, PNG_ERR_INVALID_COL_BPP, PNG_ERR_COMP_METHOD, PNG_ERR_FILTER, PNG_ERR_INTERLACED, - PNG_ERR_PAL_SIZE, PNG_ERR_TRANS_COUNT, PNG_ERR_TRANS_INVALID, PNG_ERR_INVALID_END_SIZE, PNG_ERR_NO_DATA, + PNG_ERR_PAL_SIZE, PNG_ERR_TRANS_COUNT, PNG_ERR_TRANS_INVALID, PNG_ERR_REACHED_IEND, PNG_ERR_NO_DATA, PNG_ERR_INVALID_SCANLINE, /* ZIP archive decoding errors */ ZIP_ERR_TOO_MANY_ENTRIES, ZIP_ERR_SEEK_END_OF_CENTRAL_DIR, ZIP_ERR_NO_END_OF_CENTRAL_DIR, diff --git a/src/Logger.c b/src/Logger.c index 6dc08556c..449d27a21 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -110,7 +110,7 @@ static const char* Logger_GetCCErrorDesc(cc_result res) { case PNG_ERR_PAL_SIZE: return "Invalid size of palette data"; case PNG_ERR_TRANS_COUNT: return "Invalid number of transparency entries"; case PNG_ERR_TRANS_INVALID: return "Transparency invalid for color type"; - case PNG_ERR_INVALID_END_SIZE: return "Non-empty IEND chunk"; + case PNG_ERR_REACHED_IEND: return "Incomplete PNG image data"; case PNG_ERR_NO_DATA: return "No image in PNG"; case PNG_ERR_INVALID_SCANLINE: return "Invalid PNG scanline type";