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

Index: ImageMagick-6.8.8-1/wand/mogrify.c
===================================================================
--- ImageMagick-6.8.8-1.orig/wand/mogrify.c	2013-12-01 15:47:50.000000000 +0100
+++ ImageMagick-6.8.8-1/wand/mogrify.c	2018-04-13 16:44:18.022902548 +0200
@@ -8437,7 +8437,8 @@ WandExport MagickBooleanType MogrifyImag
             Image
               *p,
               *q,
-              *swap;
+              *swap,
+              *temp;
 
             ssize_t
               swap_index;
@@ -8470,7 +8471,14 @@ WandExport MagickBooleanType MogrifyImag
             if (p == q)
               break;
             swap=CloneImage(p,0,0,MagickTrue,exception);
-            ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
+            if (swap == (Image *) NULL)
+              ThrowWandFatalException(ResourceLimitFatalError,
+                "MemoryAllocationFailed",(*images)->filename);
+            temp=CloneImage(q,0,0,MagickTrue,exception);
+            if (temp == (Image *) NULL)
+              ThrowWandFatalException(ResourceLimitFatalError,
+                "MemoryAllocationFailed",(*images)->filename);
+            ReplaceImageInList(&p,temp);
             ReplaceImageInList(&q,swap);
             *images=GetFirstImageInList(q);
             break;