Page 1 of 1

Fixed memory leak for PDF and Bitmap PSD RLE support.

Posted: 2011-03-18T01:51:41-07:00
by jeweljar
Hey, I found a tiny memory leak for PDF decoder if the delegate fails.

Code: Select all

--- ImageMagick-6.6.8-5/coders/pdf.c    2011-03-16 12:15:58.000000000 +0900
+++ ImageMagick-6.6.8-5-new/coders/pdf.c    2011-03-16 15:33:45.000000000 +0900
@@ -661,6 +661,7 @@ static Image *ReadPDFImage(const ImageIn
     { 
       ThrowFileException(exception,DelegateError,"PostscriptDelegateFailed",
         image_info->filename);
+      image=DestroyImage(image);
       return((Image *) NULL);
     }
   if (LocaleCompare(pdf_image->magick,"BMP") == 0)
And, there's a bug when decoding bitmap PSD with RLE compression.
I've patched this issue as well.

Code: Select all

--- ImageMagick-6.6.8-5/coders/psd.c    2011-03-16 12:15:58.000000000 +0900
+++ ImageMagick-6.6.8-5-new/coders/psd.c    2011-03-16 19:46:26.000000000 +0900
@@ -589,7 +589,16 @@ static MagickBooleanType ReadPSDLayer(Im
   { 
     if (image->depth == 1)
       {
-        count=ReadBlob(image,(image->columns+7)/8,pixels);
+        if (image->compression != RLECompression)
+          count=ReadBlob(image,(image->columns+7)/8,pixels);
+        else
+          {
+            count=ReadBlob(image,(size_t) offsets[y],compact_pixels);
+            if (count != (ssize_t) offsets[y])
+              break;
+            count=DecodePSDPixels((size_t) offsets[y],compact_pixels,
+              (ssize_t) 123456,(size_t) ((image->columns+7)/8),pixels);
+          }
         if (count < (ssize_t) ((image->columns+7)/8))
           break;
       }
@@ -649,9 +660,14 @@ static MagickBooleanType ReadPSDLayer(Im
               if (image->depth == 1)
                 { 
                   ssize_t
-                    bit;
+                    bit,
+                    nbits;
+
+                 nbits = image->columns - x;
+                 if (nbits > 8)
+                     nbits = 8;

-                  for (bit=0; bit < (ssize_t) (image->columns % 8); bit++)
+                  for (bit=0; bit < nbits; bit++)
                   { 
                     indexes[x]=((((unsigned char) pixel) & (0x01 << (7-bit)))
                       != 0 ? 0 : 255);
The 3rd argument '(ssize_t) 123456' to DecodePSDPixels() means nothing,
but necessary for avoiding bit-wise decoding in that function.

Re: Fixed memory leak for PDF and Bitmap PSD RLE support.

Posted: 2011-03-18T06:26:32-07:00
by magick
We applied your patches to ImageMagick 6.6.8-6 Beta available by sometime tomorrow. Thanks.