]> granicus.if.org Git - imagemagick/commitdiff
fix memory leak in miff
authorroot <356986351@qq.com>
Fri, 15 Sep 2017 16:13:56 +0000 (16:13 +0000)
committerDirk Lemstra <dlemstra@users.noreply.github.com>
Sat, 16 Sep 2017 13:29:09 +0000 (15:29 +0200)
coders/miff.c

index 7e019a00ae18c5349cfe43680abccb02a2f162c9..d77a07cddf891f56a3e00cbab9a035b585ff5e32 100644 (file)
@@ -1188,6 +1188,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
             switch (image->depth)
             {
               default:
+                colormap=(unsigned char *) RelinquishMagickMemory(colormap);
                 ThrowReaderException(CorruptImageError,
                   "ImageDepthNotSupported");
               case 8:
@@ -1258,7 +1259,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
       {
         status=SetQuantumFormat(image,quantum_info,quantum_format);
         if (status == MagickFalse)
-          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+          {
+            quantum_info=DestroyQuantumInfo(quantum_info);
+            ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+          }
       }
     packet_size=(size_t) (quantum_info->depth/8);
     if (image->storage_class == DirectClass)
@@ -1277,7 +1281,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
     compress_pixels=(unsigned char *) AcquireQuantumMemory(compress_extent,
       sizeof(*compress_pixels));
     if (compress_pixels == (unsigned char *) NULL)
-      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+      {
+        quantum_info=DestroyQuantumInfo(quantum_info);
+        ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+      }
     /*
       Read image pixels.
     */
@@ -1404,6 +1411,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                 if (length > compress_extent)
                   {
                     (void) BZ2_bzDecompressEnd(&bzip_info);
+                    quantum_info=DestroyQuantumInfo(quantum_info);
+                    compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
                     ThrowReaderException(CorruptImageError,
                       "UnableToReadImageData");
                   }
@@ -1441,6 +1450,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                 if (length > compress_extent)
                   {
                     lzma_end(&lzma_info);
+                    quantum_info=DestroyQuantumInfo(quantum_info);
+                    compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
                     ThrowReaderException(CorruptImageError,
                       "UnableToReadImageData");
                   }
@@ -1481,6 +1492,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
                 if (length > compress_extent)
                   {
                     (void) inflateEnd(&zip_info);
+                    quantum_info=DestroyQuantumInfo(quantum_info);
+                    compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
                     ThrowReaderException(CorruptImageError,
                       "UnableToReadImageData");
                   }
@@ -1555,7 +1568,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
             offset=SeekBlob(image,-((MagickOffsetType)
               bzip_info.avail_in),SEEK_CUR);
             if (offset < 0)
-              ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+              {
+                quantum_info=DestroyQuantumInfo(quantum_info);
+                compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
+                ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+              }
           }
         code=BZ2_bzDecompressEnd(&bzip_info);
         if (code != BZ_OK)
@@ -1591,7 +1608,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info,
             offset=SeekBlob(image,-((MagickOffsetType) zip_info.avail_in),
               SEEK_CUR);
             if (offset < 0)
-              ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+              {
+                quantum_info=DestroyQuantumInfo(quantum_info);
+                compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
+                ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+              }
           }
         code=inflateEnd(&zip_info);
         if (code != LZMA_OK)