File ImageMagick-CVE-2017-18209.patch of Package ImageMagick.8212

Index: ImageMagick-6.8.8-1/magick/memory-private.h
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/memory-private.h	2013-11-18 14:03:16.000000000 +0100
+++ ImageMagick-6.8.8-1/magick/memory-private.h	2018-03-14 14:25:36.031096338 +0100
@@ -41,6 +41,20 @@ extern "C" {
 #define MagickAssumeAligned(address)  (address)
 #endif
 
+static inline void *AcquireCriticalMemory(const size_t size)
+{
+  register void
+    *memory;
+
+  /*
+    Fail if memory request cannot be fulfilled.
+  */
+  memory=AcquireMagickMemory(size);
+  if (memory == (void *) NULL)
+    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  return(memory);
+}
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
Index: ImageMagick-6.8.8-1/magick/opencl.c
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/opencl.c	2013-12-22 03:08:38.000000000 +0100
+++ ImageMagick-6.8.8-1/magick/opencl.c	2018-03-14 14:30:23.472244625 +0100
@@ -59,6 +59,7 @@ Include declarations.
 #include "magick/layer.h"
 #include "magick/mime-private.h"
 #include "magick/memory_.h"
+#include "magick/memory-private.h"
 #include "magick/monitor.h"
 #include "magick/montage.h"
 #include "magick/morphology.h"
@@ -2570,7 +2571,7 @@ const char* GetOpenCLCachedFilesDirector
         (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick",home,
           DirectorySeparator);
         home=DestroyString(home);
-        temp = (char*)AcquireMagickMemory(strlen(path)+1);
+        temp = (char*)AcquireCriticalMemory(strlen(path)+1);
         CopyMagickString(temp,path,strlen(path)+1);
         status=GetPathAttributes(path,&attributes);
         if (status == MagickFalse) {
Index: ImageMagick-6.8.8-1/magick/registry.c
===================================================================
--- ImageMagick-6.8.8-1.orig/magick/registry.c	2013-12-01 15:47:50.000000000 +0100
+++ ImageMagick-6.8.8-1/magick/registry.c	2018-03-14 14:25:36.031096338 +0100
@@ -46,6 +46,7 @@
 #include "magick/image.h"
 #include "magick/list.h"
 #include "magick/memory_.h"
+#include "magick/memory-private.h"
 #include "magick/registry.h"
 #include "magick/splay-tree.h"
 #include "magick/string_.h"
@@ -514,9 +515,7 @@ MagickExport MagickBooleanType SetImageR
   }
   if (clone_value == (void *) NULL)
     return(MagickFalse);
-  registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info));
-  if (registry_info == (RegistryInfo *) NULL)
-    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  registry_info=(RegistryInfo *) AcquireCriticalMemory(sizeof(*registry_info));
   (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info));
   registry_info->type=type;
   registry_info->value=clone_value;