Fixed memory leak for PDF and Bitmap PSD RLE support.

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jeweljar
Posts: 2
Joined: 2011-01-24T02:29:03-07:00
Authentication code: 8675308

Fixed memory leak for PDF and Bitmap PSD RLE support.

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

We applied your patches to ImageMagick 6.6.8-6 Beta available by sometime tomorrow. Thanks.
Post Reply