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

From 6c6abed989ea4a3ef472db65ab487c1809a3a718 Mon Sep 17 00:00:00 2001
From: Dirk Lemstra <dirk@git.imagemagick.org>
Date: Tue, 2 May 2017 08:26:36 +0200
Subject: [PATCH] Fixed various leaks reported in #460.

---
 coders/pdb.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Index: ImageMagick-6.8.8-1/coders/pdb.c
===================================================================
--- ImageMagick-6.8.8-1.orig/coders/pdb.c	2017-06-28 14:45:59.951947370 +0200
+++ ImageMagick-6.8.8-1/coders/pdb.c	2017-06-28 14:47:58.830004087 +0200
@@ -421,19 +421,25 @@ static Image *ReadPDBImage(const ImageIn
     case 0:
     {
       image->compression=NoCompression;
-      count=(ssize_t) ReadBlob(image, packets * image -> rows, pixels);
+      count=(ssize_t) ReadBlob(image,packets*image->rows,pixels);
       break;
     }
     case 1:
     {
       image->compression=RLECompression;
-      if (!DecodeImage(image, pixels, packets * image -> rows))
-        ThrowReaderException( CorruptImageError, "RLEDecoderError" ); /* TS */
+      if (!DecodeImage(image,pixels,packets*image->rows))
+        {
+          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+          ThrowReaderException( CorruptImageError,"RLEDecoderError"); /* TS */
+        }
       break;
     }
     default:
-      ThrowReaderException(CorruptImageError,
-         "UnrecognizedImageCompressionType" );
+      {
+        pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+        ThrowReaderException(CorruptImageError,
+          "UnrecognizedImageCompressionType");
+      }
   }
   p=pixels;
   switch (bits_per_pixel)
@@ -534,7 +540,10 @@ static Image *ReadPDBImage(const ImageIn
       break;
     }
     default:
+    {
+      pixels=(unsigned char *) RelinquishMagickMemory(pixels);
       ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+    }
   }
 
   pixels=(unsigned char *) RelinquishMagickMemory(pixels);