Index: GraphicsMagick-1.2.5/coders/png.c
===================================================================
--- GraphicsMagick-1.2.5.orig/coders/png.c	2016-12-13 17:53:56.322813506 +0100
+++ GraphicsMagick-1.2.5/coders/png.c	2016-12-13 17:55:13.528846219 +0100
@@ -67,6 +67,7 @@
 #include "magick/monitor.h"
 #include "magick/profile.h"
 #include "magick/quantize.h"
+#include "magick/resource.h"
 #include "magick/static.h"
 #include "magick/semaphore.h"
 #include "magick/tempfile.h"
@@ -2795,6 +2796,9 @@ static Image *ReadOneJNGImage(MngInfo *m
     jng_height,
     jng_width;
 
+  magick_int64_t
+    pixels_resource;
+
   png_byte
     jng_color_type,
     jng_image_sample_depth,
@@ -2864,6 +2868,9 @@ static Image *ReadOneJNGImage(MngInfo *m
   read_JSEP=False;
   reading_idat=False;
   skip_to_iend=False;
+
+  pixels_resource = GetMagickResourceLimit(PixelsResource);
+
   for (;;)
     {
       char
@@ -2965,6 +2972,10 @@ static Image *ReadOneJNGImage(MngInfo *m
             }
           if (length)
             MagickFreeMemory(chunk);
+
+
+          SetMagickResourceLimit(PixelsResource,jng_width*jng_height);
+
           continue;
         }
 
@@ -3361,6 +3372,9 @@ static Image *ReadOneJNGImage(MngInfo *m
   if (logging)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                           "  exit ReadOneJNGImage()");
+
+  SetMagickResourceLimit(PixelsResource,pixels_resource);
+
   return (image);
 }
 
Index: GraphicsMagick-1.2.5/magick/resource.c
===================================================================
--- GraphicsMagick-1.2.5.orig/magick/resource.c	2008-04-16 06:13:37.000000000 +0200
+++ GraphicsMagick-1.2.5/magick/resource.c	2016-12-13 18:15:55.176241505 +0100
@@ -310,6 +310,48 @@ MagickExport magick_int64_t GetMagickRes
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   G e t M a g i c k R e s o u r c e L i m i t                               %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetMagickResourceLimit() returns the current maximum limit for the
+%  specified resource type.
+%
+%  The format of the GetMagickResourceLimit() method is:
+%
+%      magick_uint64_t GetMagickResourceLimit(const ResourceType type)
+%
+%  A description of each parameter follows:
+%
+%    o type: The type of resource.
+%
+%
+*/
+MagickExport magick_int64_t GetMagickResourceLimit(const ResourceType type)
+{
+  ResourceInfo
+    *info;
+
+  magick_int64_t
+    resource;
+
+  resource=0;
+  LockSemaphoreInfo(resource_semaphore);
+
+  if ((info=GetResourceInfo(type)))
+    resource=info->limit;
+
+  UnlockSemaphoreInfo(resource_semaphore);
+  return(resource);
+}
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 +   I n i t i a l i z e M a g i c k R e s o u r c e s                         %
 %                                                                             %
 %                                                                             %
Index: GraphicsMagick-1.2.5/magick/resource.h
===================================================================
--- GraphicsMagick-1.2.5.orig/magick/resource.h	2008-04-16 06:13:37.000000000 +0200
+++ GraphicsMagick-1.2.5/magick/resource.h	2016-12-13 18:13:02.915218370 +0100
@@ -37,7 +37,8 @@ extern MagickExport MagickPassFail
   SetMagickResourceLimit(const ResourceType type,const magick_int64_t limit);
 
 extern MagickExport magick_int64_t
-  GetMagickResource(const ResourceType type);
+  GetMagickResource(const ResourceType type),
+  GetMagickResourceLimit(const ResourceType type);
 
 extern MagickExport void
   DestroyMagickResources(void),
