From f917165411e409341e7ff8b41217318584633029 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 10 Jun 2020 11:29:54 +0300 Subject: [PATCH] Fix bug 45556 --- DesktopEditor/cximage/CxImage/ximapng.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/DesktopEditor/cximage/CxImage/ximapng.cpp b/DesktopEditor/cximage/CxImage/ximapng.cpp index 8e54506d38..e1cb746ff6 100644 --- a/DesktopEditor/cximage/CxImage/ximapng.cpp +++ b/DesktopEditor/cximage/CxImage/ximapng.cpp @@ -41,6 +41,8 @@ bool CxImagePNG::Decode(CxFile *hFile) png_info *info_ptr; uint8_t *row_pointers=NULL; CImageIterator iter(this); + bool is_read_end_start = false; + bool is_read_end = false; cx_try { @@ -296,15 +298,23 @@ bool CxImagePNG::Decode(CxFile *hFile) row_pointers = NULL; /* read the rest of the file, getting any additional chunks in info_ptr - REQUIRED */ - png_read_end(png_ptr, info_ptr); + is_read_end_start = true; + png_read_end(png_ptr, info_ptr); + is_read_end = true; /* clean up after the read, and free any memory allocated - REQUIRED */ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); } cx_catch { - if (strcmp(message,"")) strncpy(info.szLastError,message,255); - if (info.nEscape == -1 && info.dwType == CXIMAGE_FORMAT_PNG) return true; - return false; + if (!is_read_end_start || is_read_end) { + if (strcmp(message,"")) strncpy(info.szLastError,message,255); + if (info.nEscape == -1 && info.dwType == CXIMAGE_FORMAT_PNG) return true; + return false; + } + else { + /* clean up after the read, and free any memory allocated - REQUIRED */ + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); + } } /* that's it */ return true;