Index: GraphicsMagick-1.2.5/coders/png.c
===================================================================
--- GraphicsMagick-1.2.5.orig/coders/png.c	2018-01-17 12:19:24.179503368 +0100
+++ GraphicsMagick-1.2.5/coders/png.c	2018-01-17 12:28:47.884682677 +0100
@@ -1407,15 +1407,15 @@ png_read_raw_profile(Image *image, const
   /* allocate space */
   if (length == 0)
     {
-      (void) ThrowException(&image->exception,CoderError,UnableToCopyProfile,
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                             "invalid profile length");
       return (False);
     }
   info=MagickAllocateMemory(unsigned char *,length);
   if (info == (unsigned char *) NULL)
     {
-      (void) ThrowException(&image->exception,ResourceLimitError,
-                            MemoryAllocationFailed,"unable to copy profile");
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                            "Unable to copy profile");
       return (False);
     }
   /* copy profile, skipping white space and column 1 "=" signs */
@@ -1427,8 +1427,8 @@ png_read_raw_profile(Image *image, const
         {
           if (*sp == '\0')
             {
-              (void) ThrowException(&image->exception,CoderError,
-                                    UnableToCopyProfile,"ran out of data");
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "ran out of profile data");
               MagickFreeMemory(info);
               return (False);
             }
@@ -1462,8 +1462,8 @@ png_read_raw_profile(Image *image, const
   if(SetImageProfile(image,profile_name,info,length) == MagickFail)
     {
       MagickFreeMemory(info);
-      (void) ThrowException(&image->exception,ResourceLimitError,
-                            MemoryAllocationFailed,"unable to copy profile");
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                            "unable to copy profile");
       return (False);
     }
   MagickFreeMemory(info);
@@ -3386,6 +3386,10 @@ static Image *ReadOneJNGImage(MngInfo *m
   image->rows=jng_height;
   image->columns=jng_width;
   length=MagickArraySize(image->columns,sizeof(PixelPacket));
+  if ((jng_height == 0 || jng_width == 0) && logging)
+    (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                          "    jng_width=%lu jng_height=%lu",
+                          (unsigned long)jng_width,(unsigned long)jng_height);
   for (y=0; y < (long) image->rows; y++)
     {
       s=AcquireImagePixels(jng_image,0,y,image->columns,1,&image->exception);
@@ -3429,33 +3433,60 @@ static Image *ReadOneJNGImage(MngInfo *m
 
           jng_image=ReadImage(alpha_image_info,exception);
 
-          for (y=0; y < (long) image->rows; y++)
+          if (jng_image == (Image *)NULL)
+            {
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                   "    jng_image is NULL.");
+              DestroyJNG(NULL,&color_image,&color_image_info,
+                &alpha_image,&alpha_image_info);
+            }
+          else
             {
-              s=AcquireImagePixels(jng_image,0,y,image->columns,1,
-                                   &image->exception);
-              if (image->matte)
+              if (logging)
                 {
-                  q=SetImagePixels(image,0,y,image->columns,1);
-                  if (q == (PixelPacket *) NULL)
-                    break;
-                  for (x=(long) image->columns; x > 0; x--,q++,s++)
-                    q->opacity=(Quantum) MaxRGB-s->red;
+                  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                       "    Read jng_image.");
+                  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                       "      jng_image->width=%lu, jng_image->height=%lu",
+                       (unsigned long)jng_width,(unsigned long)jng_height);
+                  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                       "      image->rows=%lu, image->columns=%lu",
+                      (unsigned long)image->rows,
+                      (unsigned long)image->columns);
                 }
-              else
+ 
+              for (y=0; y < (long) image->rows; y++)
                 {
-                  q=SetImagePixels(image,0,y,image->columns,1);
-                  if (q == (PixelPacket *) NULL)
-                    break;
-                  for (x=(long) image->columns; x > 0; x--,q++,s++)
+                  s=AcquireImagePixels(jng_image,0,y,image->columns,1,
+                                       &image->exception);
+                  if (image->matte)
+                    {
+                      q=SetImagePixels(image,0,y,image->columns,1);
+                      for (x=(long) image->columns; x > 0; x--,q++,s++)
+                        q->opacity=(Quantum) MaxRGB-s->red;
+                    }
+                  else
                     {
-                      q->opacity=(Quantum) MaxRGB-s->red;
-                      if (q->opacity != OpaqueOpacity)
-                        image->matte=True;
+                      q=SetImagePixels(image,0,y,image->columns,1);
+                      for (x=(long) image->columns; x > 0; x--,q++,s++)
+                        {
+                          q->opacity=(Quantum) MaxRGB-s->red;
+                          if (q->opacity != OpaqueOpacity)
+                            image->matte=MagickTrue;
+                        }
                     }
+                  if (!SyncImagePixels(image))
+                    break;
                 }
-              if (!SyncImagePixels(image))
-                break;
+              (void) LiberateUniqueFileResource(alpha_image->filename);
+              DestroyJNG(NULL,&color_image,&color_image_info,
+                &alpha_image,&alpha_image_info);
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                  " Destroy the JNG image");
+              DestroyImage(jng_image);
+              jng_image = (Image *)NULL;
             }
+
           (void) LiberateUniqueFileResource(alpha_image->filename);
           DestroyJNG(NULL,color_image,color_image_info,
                      alpha_image,alpha_image_info);
