From ef632a5ea233e389489bec72c8efad004eff8f58 Mon Sep 17 00:00:00 2001 From: cristy Date: Tue, 3 Dec 2013 11:06:33 +0000 Subject: [PATCH] --- coders/webp.c | 60 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/coders/webp.c b/coders/webp.c index e1b4b992f..42a5ea7b1 100644 --- a/coders/webp.c +++ b/coders/webp.c @@ -13,11 +13,11 @@ % 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; -- 2.40.0