Index: GraphicsMagick-1.2.5/coders/png.c
===================================================================
--- GraphicsMagick-1.2.5.orig/coders/png.c	2018-01-17 08:29:53.823597122 +0100
+++ GraphicsMagick-1.2.5/coders/png.c	2018-01-17 08:45:16.339304826 +0100
@@ -2933,7 +2933,9 @@ static Image *ReadOneJNGImage(MngInfo *m
       {
         DestroyJNG(NULL,color_image,color_image_info,
                    alpha_image,alpha_image_info);
-        ThrowReaderException(CorruptImageError,CorruptImage,image);
+        (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                              "chunk length (%lu) > PNG_MAX_UINT",length);
+        return ((Image*)NULL);
       }
       chunk=(unsigned char *) NULL;
       p=NULL;
@@ -2944,8 +2946,9 @@ static Image *ReadOneJNGImage(MngInfo *m
           {
             DestroyJNG(chunk,color_image,color_image_info,
                        alpha_image,alpha_image_info);
-            ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
-                                 image);
+            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                  "    Could not allocate chunk memory");
+            return ((Image*)NULL);
           }
           for (i=0; i < (long) length; i++)
             chunk[i]=ReadBlobByte(image);
@@ -3052,8 +3055,9 @@ static Image *ReadOneJNGImage(MngInfo *m
           {
             DestroyJNG(chunk,color_image,color_image_info,
                        alpha_image,alpha_image_info);
-            ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
-                                 image);
+            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                  "    could not allocate color_image_info");
+            return ((Image *)NULL);
           }
           GetImageInfo(color_image_info);
           color_image=AllocateImage(color_image_info);
@@ -3061,8 +3065,9 @@ static Image *ReadOneJNGImage(MngInfo *m
           {
             DestroyJNG(chunk,color_image,color_image_info,
                        alpha_image,alpha_image_info);
-            ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
-                                 image);
+            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                  "    could not allocate color_image");
+            return ((Image *)NULL);
           }
           if (logging)
             (void) LogMagickEvent(CoderEvent,GetMagickModule(),
@@ -3074,7 +3079,9 @@ static Image *ReadOneJNGImage(MngInfo *m
           {
             DestroyJNG(chunk,color_image,color_image_info,
                        alpha_image,alpha_image_info);
-            ThrowReaderException(CoderError,UnableToOpenBlob,color_image);
+            (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                  "    could not open alpha_image blob");
+            return ((Image *)NULL);
           }
 
           if (!image_info->ping && jng_color_type >= 12)
@@ -3085,8 +3092,9 @@ static Image *ReadOneJNGImage(MngInfo *m
               {
                 DestroyJNG(chunk,color_image,color_image_info,
                            alpha_image,alpha_image_info);
-                ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
-                                     image);
+                (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                      "    could not allocate alpha_image_alpha");
+                return ((Image *)NULL);
               }
               GetImageInfo(alpha_image_info);
               alpha_image=AllocateImage(alpha_image_info);
@@ -3094,8 +3102,9 @@ static Image *ReadOneJNGImage(MngInfo *m
                 {
                   DestroyJNG(chunk,color_image,color_image_info,
                              alpha_image,alpha_image_info);
-                  ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
-                                       alpha_image);
+                  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                        "    could not allocate alpha_image");
+                  return ((Image *)NULL);
                 }
               if (logging)
                 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
@@ -3108,7 +3117,7 @@ static Image *ReadOneJNGImage(MngInfo *m
                 DestroyJNG(chunk,color_image,color_image_info,
                            alpha_image,alpha_image_info);
                 DestroyImage(alpha_image);
-                ThrowReaderException(CoderError,UnableToOpenBlob,image);
+                return ((Image *)NULL);
               }
               if (jng_alpha_compression_method == 0)
                 {
@@ -3475,7 +3484,9 @@ static Image *ReadOneJNGImage(MngInfo *m
 
   SetMagickResourceLimit(PixelsResource,pixels_resource);
 
-  return (image);
+  if (image != (Image *)NULL)
+    DestroyImageList(image);
+  return((Image *)NULL);
 }
 
 /*
