]> granicus.if.org Git - imagemagick/commitdiff
Fixed incorrect check for memory request.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sat, 5 May 2018 08:19:56 +0000 (10:19 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sat, 5 May 2018 08:20:20 +0000 (10:20 +0200)
MagickCore/memory-private.h
MagickCore/memory.c
coders/miff.c

index 4c524b0f73f4c064421131cda430cca8ea10e323..09d86721f1b02ddde1dff27e7a67129c97914d7b 100644 (file)
@@ -46,6 +46,9 @@ extern "C" {
 MagickExport MagickBooleanType 
   HeapOverflowSanityCheck(const size_t,const size_t) magick_alloc_sizes(1,2);
 
+MagickExport size_t
+  GetMaxMemoryRequest(void);
+
 extern MagickPrivate void
   ResetMaxMemoryRequest(void),
   ResetVirtualAnonymousMemory(void);
index 4ef4386141424d4c26b6bc84aed377a535ef83b1..85e16873683e46f179865c36efa1815bd34776f9 100644 (file)
@@ -582,19 +582,7 @@ MagickExport MemoryInfo *AcquireVirtualMemory(const size_t count,
 
   if (HeapOverflowSanityCheck(count,quantum) != MagickFalse)
     return((MemoryInfo *) NULL);
-  if (max_memory_request == 0)
-    {
-      max_memory_request=(size_t) MagickULLConstant(~0);
-      value=GetPolicyValue("system:max-memory-request");
-      if (value != (char *) NULL)
-        {
-          /*
-            The security policy sets a max memory request limit.
-          */
-          max_memory_request=StringToSizeType(value,100.0);
-          value=DestroyString(value);
-        }
-    }
+  (void) GetMaxMemoryRequest();
   if (virtual_anonymous_memory == 0)
     {
       virtual_anonymous_memory=1;
@@ -901,6 +889,45 @@ MagickExport void GetMagickMemoryMethods(
 %                                                                             %
 %                                                                             %
 %                                                                             %
++   G e t M a x M e m o r y R e q u e s t                                     %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetMaxMemoryRequest() returns the max_memory_request value.
+%
+%  The format of the GetMaxMemoryRequest method is:
+%
+%      size_t GetMaxMemoryRequest(void)
+%
+*/
+MagickExport size_t GetMaxMemoryRequest(void)
+{
+  if (max_memory_request == 0)
+    {
+      char
+        *value;
+
+      max_memory_request=(size_t) MagickULLConstant(~0);
+      value=GetPolicyValue("system:max-memory-request");
+      if (value != (char *) NULL)
+        {
+          /*
+            The security policy sets a max memory request limit.
+          */
+          max_memory_request=StringToSizeType(value,100.0);
+          value=DestroyString(value);
+        }
+    }
+  return(max_memory_request);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   G e t V i r t u a l M e m o r y B l o b                                   %
 %                                                                             %
 %                                                                             %
@@ -1167,7 +1194,7 @@ MagickExport void *ResetMagickMemory(void *memory,int byte,const size_t size)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ResetMaxMemoryRequest() resets the anonymous_memory value.
+%  ResetMaxMemoryRequest() resets the max_memory_request value.
 %
 %  The format of the ResetMaxMemoryRequest method is:
 %
@@ -1190,7 +1217,7 @@ MagickPrivate void ResetMaxMemoryRequest(void)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ResetVirtualAnonymousMemory() resets the anonymous_memory value.
+%  ResetVirtualAnonymousMemory() resets the virtual_anonymous_memory value.
 %
 %  The format of the ResetVirtualAnonymousMemory method is:
 %
index 6e40a9d34822e09a134f56426ae823c3b730cf55..cb0b9ae9f3cdfe708bb7d4352e6609e00986947a 100644 (file)
@@ -167,19 +167,12 @@ static void *AcquireCompressionMemory(void *context,
   size_t
     extent;
 
+  (void) context;
   if (HeapOverflowSanityCheck(items,size) != MagickFalse)
     return((void *) NULL);
   extent=items*size;
-  /* Check if the buffer is big enough when we get a large request */
-  if ((context != (void *) NULL) && (extent > 2000000))
-    {
-      Image
-        *image;
-
-      image=(Image *) context;
-      if ((MagickSizeType) extent > GetBlobSize(image))
-        return((void *) NULL);
-    }
+  if (extent > GetMaxMemoryRequest())
+    return((void *) NULL);
   return(AcquireMagickMemory(extent));
 }
 
@@ -1567,7 +1560,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
             if (length == 0)
               {
                 count=ReadBlob(image,packet_size,pixels);
-                if (count != packet_size)
+                if (count != (ssize_t) packet_size)
                   ThrowMIFFException(CorruptImageError,"UnableToReadImageData");
                 PushRunlengthPacket(image,pixels,&length,&pixel,exception);
               }
@@ -1591,7 +1584,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
         default:
         {
           count=ReadBlob(image,packet_size*image->columns,pixels);
-          if (count != (packet_size*image->columns))
+          if (count != (ssize_t) (packet_size*image->columns))
             ThrowMIFFException(CorruptImageError,"UnableToReadImageData");
           (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
             quantum_type,pixels,exception);