]> granicus.if.org Git - imagemagick/commitdiff
DecodeImage should return null when decoding fails (https://bugs.chromium.org/p/oss...
authorDirk Lemstra <dirk@git.imagemagick.org>
Fri, 13 Apr 2018 20:18:52 +0000 (22:18 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Fri, 13 Apr 2018 20:18:52 +0000 (22:18 +0200)
coders/pict.c

index d010e44d3d86a89afee7eff5ae950624b9125d2b..e648ca014b10f64899dc577d823ee8bad3c91682 100644 (file)
@@ -394,9 +394,11 @@ static unsigned char *ExpandBuffer(unsigned char *pixels,
 }
 
 static unsigned char *DecodeImage(Image *blob,Image *image,
-  size_t bytes_per_line,const unsigned int bits_per_pixel,size_t *extent,
-  ExceptionInfo *exception)
+  size_t bytes_per_line,const unsigned int bits_per_pixel,size_t *extent)
 {
+  MagickBooleanType
+    status;
+
   MagickSizeType
     number_pixels;
 
@@ -460,6 +462,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
       return((unsigned char *) NULL);
     }
   (void) memset(scanline,0,2*row_bytes*sizeof(*scanline));
+  status=MagickTrue;
   if (bytes_per_line < 8)
     {
       /*
@@ -472,22 +475,20 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
         count=ReadBlob(blob,(size_t) number_pixels,scanline);
         if (count != (ssize_t) number_pixels)
           {
-            (void) ThrowMagickException(exception,GetMagickModule(),
-              CorruptImageError,"UnableToUncompressImage","`%s'",
-              image->filename);
+            status=MagickFalse;
             break;
           }
         p=ExpandBuffer(scanline,&number_pixels,bits_per_pixel);
         if ((q+number_pixels) > (pixels+(*extent)))
           {
-            (void) ThrowMagickException(exception,GetMagickModule(),
-              CorruptImageError,"UnableToUncompressImage","`%s'",
-              image->filename);
+            status=MagickFalse;
             break;
           }
         (void) memcpy(q,p,(size_t) number_pixels);
       }
       scanline=(unsigned char *) RelinquishMagickMemory(scanline);
+      if (status == MagickFalse)
+        pixels=(unsigned char *) RelinquishMagickMemory(pixels);
       return(pixels);
     }
   /*
@@ -502,15 +503,13 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
       scanline_length=(size_t) ReadBlobByte(blob);
     if ((scanline_length >= row_bytes) || (scanline_length == 0))
       {
-        //(void) ThrowMagickException(exception,GetMagickModule(),
-        //  CorruptImageError,"UnableToUncompressImage","`%s'",image->filename);
+        status=MagickFalse;
         break;
       }
     count=ReadBlob(blob,scanline_length,scanline);
     if (count != (ssize_t) scanline_length)
       {
-        (void) ThrowMagickException(exception,GetMagickModule(),
-          CorruptImageError,"UnableToUncompressImage","`%s'",image->filename);
+        status=MagickFalse;
         break;
       }
     for (j=0; j < (ssize_t) scanline_length; )
@@ -539,6 +538,8 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
         }
   }
   scanline=(unsigned char *) RelinquishMagickMemory(scanline);
+  if (status == MagickFalse)
+    pixels=(unsigned char *) RelinquishMagickMemory(pixels);
   return(pixels);
 }
 \f
@@ -1231,12 +1232,12 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
             if ((code != 0x9a) && (code != 0x9b) &&
                 (bytes_per_line & 0x8000) == 0)
               pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line,1,
-                &extent,exception);
+                &extent);
             else
               pixels=DecodeImage(image,tile_image,(size_t) bytes_per_line,
-                (unsigned int) pixmap.bits_per_pixel,&extent,exception);
+                (unsigned int) pixmap.bits_per_pixel,&extent);
             if (pixels == (unsigned char *) NULL)
-              ThrowPICTException(ResourceLimitError,"MemoryAllocationFailed");
+              ThrowPICTException(CorruptImageError,"UnableToUncompressImage");
             /*
               Convert PICT tile image to pixel packets.
             */