File ImageMagick-CVE-2018-6405,11656.patch of Package ImageMagick.8212

Index: ImageMagick-6.8.8-1/coders/dcm.c
===================================================================
--- ImageMagick-6.8.8-1.orig/coders/dcm.c	2018-02-12 16:39:08.258533586 +0100
+++ ImageMagick-6.8.8-1/coders/dcm.c	2018-02-12 16:39:08.266533719 +0100
@@ -2800,6 +2800,14 @@ static Image *ReadDCMImage(const ImageIn
 { \
   if (data != (unsigned char *) NULL) \
     data=(unsigned char *) RelinquishMagickMemory(data); \
+  if (graymap != (int *) NULL) \
+    graymap=(int *) RelinquishMagickMemory(graymap); \
+  if (bluemap != (int *) NULL) \
+    bluemap=(int *) RelinquishMagickMemory(bluemap); \
+  if (greenmap != (int *) NULL) \
+    greenmap=(int *) RelinquishMagickMemory(greenmap); \
+  if (redmap != (int *) NULL) \
+    redmap=(int *) RelinquishMagickMemory(redmap); \
   if (stream_info != (DCMStreamInfo *) NULL) \
     stream_info=(DCMStreamInfo *) RelinquishMagickMemory(stream_info); \
   ThrowReaderException((exception),(message)); \
@@ -2902,7 +2910,11 @@ static Image *ReadDCMImage(const ImageIn
     Read DCM preamble.
   */
   data=(unsigned char *) NULL;
-  stream_info=(DCMStreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
+  redmap=(int *) NULL;
+  greenmap=(int *) NULL;
+  bluemap=(int *) NULL;
+  graymap=(int *) NULL;
+ stream_info=(DCMStreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
   if (stream_info == (DCMStreamInfo *) NULL)
     ThrowDCMReaderException(ResourceLimitError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
@@ -2929,10 +2941,6 @@ static Image *ReadDCMImage(const ImageIn
   explicit_vr[2]='\0';
   explicit_file=MagickFalse;
   colors=0;
-  redmap=(int *) NULL;
-  greenmap=(int *) NULL;
-  bluemap=(int *) NULL;
-  graymap=(int *) NULL;
   height=0;
   max_value=255UL;
   mask=0xffff;
@@ -3320,6 +3328,8 @@ static Image *ReadDCMImage(const ImageIn
               break;
             colors=(size_t) (length/bytes_per_pixel);
             datum=(int) colors;
+            if (graymap != (int *) NULL)
+              graymap=(int *) RelinquishMagickMemory(graymap);
             graymap=(int *) AcquireQuantumMemory((size_t) colors,
               sizeof(*graymap));
             if (graymap == (int *) NULL)
@@ -3344,6 +3354,8 @@ static Image *ReadDCMImage(const ImageIn
               break;
             colors=(size_t) (length/2);
             datum=(int) colors;
+            if (redmap != (int *) NULL)
+              redmap=(int *) RelinquishMagickMemory(redmap);
             redmap=(int *) AcquireQuantumMemory((size_t) colors,
               sizeof(*redmap));
             if (redmap == (int *) NULL)
@@ -3373,6 +3385,8 @@ static Image *ReadDCMImage(const ImageIn
               break;
             colors=(size_t) (length/2);
             datum=(int) colors;
+            if (greenmap != (int *) NULL)
+              greenmap=(int *) RelinquishMagickMemory(greenmap);
             greenmap=(int *) AcquireQuantumMemory((size_t) colors,
               sizeof(*greenmap));
             if (greenmap == (int *) NULL)
@@ -3402,6 +3416,8 @@ static Image *ReadDCMImage(const ImageIn
               break;
             colors=(size_t) (length/2);
             datum=(int) colors;
+            if (bluemap != (int *) NULL)
+              bluemap=(int *) RelinquishMagickMemory(bluemap);
             bluemap=(int *) AcquireQuantumMemory((size_t) colors,
               sizeof(*bluemap));
             if (bluemap == (int *) NULL)