What seems to be happening is that, when reading directly from a file, we always get a FileStream image blob type. This makes sense.
For the case where we don't explicitly specify the input format, the STDIN stream gets written to a temporary file and ends up as a FileStream image blob type by the time it gets to the WebP reader.
For the case where we do explicitly specify the input format, the STDIN stream gets passed to the WebP reader directly as a StandardStream image blob type.
GetBlobSize returns the appropriate size for FileStream image blob types, it returns 0 for StandardStream image blob types because it doesn't know how much data it's going to get.
WebP reads the entire image data in to memory and allocates this memory using the size given by GetBlobSize (which for the StandardStream case returns 0). The allocation fails because it was asked to allocate nothing.
I've written a patch that reads the file size from the WebP header instead of depending on the reported blob size. Here it is:
Code: Select all
diff -rupN ImageMagick-6.8.9-5.old/coders/webp.c ImageMagick-6.8.9-5/coders/webp.c
--- ImageMagick-6.8.9-5.old/coders/webp.c 2014-04-19 21:41:29.000000000 -0400
+++ ImageMagick-6.8.9-5/coders/webp.c 2014-07-08 22:33:29.000000000 -0400
@@ -223,6 +223,7 @@ static Image *ReadWEBPImage(const ImageI
y;
unsigned char
+ header[12],
*stream;
WebPDecoderConfig
@@ -254,12 +255,21 @@ static Image *ReadWEBPImage(const ImageI
if (WebPInitDecoderConfig(&configure) == 0)
ThrowReaderException(ResourceLimitError,"UnableToDecodeImageFile");
webp_image->colorspace=MODE_RGBA;
- length=(size_t) GetBlobSize(image);
+ count=ReadBlob(image,12,header);
+ if (count != 12)
+ ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
+ status=IsWEBP(header,count);
+ if (status == MagickFalse)
+ ThrowReaderException(CorruptImageError,"CorruptImage");
+ length=(size_t) (ReadWebPLSBWord(header+4)+8);
+ if (length < 12)
+ ThrowReaderException(CorruptImageError,"CorruptImage");
stream=(unsigned char *) AcquireQuantumMemory(length,sizeof(*stream));
if (stream == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- count=ReadBlob(image,length,stream);
- if (count != (ssize_t) length)
+ memcpy(stream,header,12);
+ count=ReadBlob(image,length-12,stream+12);
+ if (count != (ssize_t) (length-12))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
webp_status=WebPGetFeatures(stream,length,features);
if (webp_status == VP8_STATUS_OK)