(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Tue, 3 Dec 2013 11:06:33 +0000 (11:06 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Tue, 3 Dec 2013 11:06:33 +0000 (11:06 +0000)
coders/webp.c

index e1b4b992fc717ffefe5344f3d78501bfd603bc49..42a5ea7b195870243b9769566474351e81aeb392 100644 (file)
 %                         Read/Write WebP Image Format                        %
 %                                                                             %
 %                              Software Design                                %
-%                                   Cristy                                    %
+%                                John Cristy                                  %
 %                                 March 2011                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -177,7 +177,7 @@ static MagickBooleanType IsWEBPImageLossless(const unsigned char *stream,
     Read simple header.
   */
   if (stream[VP8_CHUNK_INDEX] != EXTENDED_HEADER)
-   return(stream[VP8_CHUNK_INDEX] == LOSSLESS_FLAG ? MagickTrue : MagickFalse);
+    return(stream[VP8_CHUNK_INDEX] == LOSSLESS_FLAG ? MagickTrue : MagickFalse);
   /*
     Read extended header.
   */
@@ -206,6 +206,9 @@ static Image *ReadWEBPImage(const ImageInfo *image_info,
   Image
     *image;
 
+  int
+    webp_status;
+
   MagickBooleanType
     status;
 
@@ -250,6 +253,7 @@ static Image *ReadWEBPImage(const ImageInfo *image_info,
     }
   if (WebPInitDecoderConfig(&configure) == 0)
     ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile");
+  webp_image->colorspace=MODE_RGBA;
   length=(size_t) GetBlobSize(image);
   stream=(unsigned char *) AcquireQuantumMemory(length,sizeof(*stream));
   if (stream == (unsigned char *) NULL)
@@ -257,21 +261,51 @@ static Image *ReadWEBPImage(const ImageInfo *image_info,
   count=ReadBlob(image,length,stream);
   if (count != (ssize_t) length)
     ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
-  if (WebPGetFeatures(stream,length,features) != 0)
+  webp_status=WebPGetFeatures(stream,length,features);
+  if (webp_status == VP8_STATUS_OK)
     {
-      stream=(unsigned char*) RelinquishMagickMemory(stream);
-      ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile");
+      image->columns=(size_t) webp_image->width;
+      image->rows=(size_t) webp_image->height;
+      image->depth=8;
+      image->alpha_trait=features->has_alpha != 0 ? BlendPixelTrait :
+        UndefinedPixelTrait;
+      if (image_info->ping != MagickFalse)
+        {
+          stream=(unsigned char*) RelinquishMagickMemory(stream);
+          (void) CloseBlob(image);
+          return(GetFirstImageInList(image));
+        }
+      webp_status=WebPDecode(stream,length,&configure);
     }
-  webp_image->colorspace=MODE_RGBA;
-  if (WebPDecode(stream,length,&configure) != 0)
+  if (webp_status != VP8_STATUS_OK)
     {
       stream=(unsigned char*) RelinquishMagickMemory(stream);
-      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+      switch (webp_status)
+      {
+        case VP8_STATUS_OUT_OF_MEMORY:
+        {
+          ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+          break;
+        }
+        case VP8_STATUS_BITSTREAM_ERROR:
+        {
+          ThrowReaderException(CorruptImageError,"CorruptImage");
+          break;
+        }
+        case VP8_STATUS_UNSUPPORTED_FEATURE:
+        {
+          ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported");
+          break;
+        }
+        case VP8_STATUS_NOT_ENOUGH_DATA:
+        {
+          ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
+          break;
+        }
+        default:
+          ThrowReaderException(CorruptImageError,"CorruptImage");
+      }
     }
-  image->columns=(size_t) webp_image->width;
-  image->rows=(size_t) webp_image->height;
-  image->alpha_trait=features->has_alpha != 0 ? BlendPixelTrait :
-    UndefinedPixelTrait;
   if (IsWEBPImageLossless(stream,length) != MagickFalse)
     image->quality=100;
   p=webp_image->u.RGBA.rgba;