From 20cc087e17cf68d42f5e39025b2d213e152f115f Mon Sep 17 00:00:00 2001 From: cristy Date: Mon, 20 Aug 2012 00:01:19 +0000 Subject: [PATCH] --- MagickCore/stream.c | 63 ++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/MagickCore/stream.c b/MagickCore/stream.c index 2c0453b51..5bd9832b7 100644 --- a/MagickCore/stream.c +++ b/MagickCore/stream.c @@ -619,8 +619,8 @@ static const Quantum *GetVirtualPixelsStream(const Image *image) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% GetVirtualMetacontentFromStream() returns the associated pixel -% channels corresponding with the last call to QueueAuthenticPixelsStream() or +% GetVirtualMetacontentFromStream() returns the associated pixel channels +% corresponding with the last call to QueueAuthenticPixelsStream() or % GetVirtualPixelStream(). % % The format of the GetVirtualMetacontentFromStream() method is: @@ -632,8 +632,7 @@ static const Quantum *GetVirtualPixelsStream(const Image *image) % o image: the image. % */ -static const void *GetVirtualMetacontentFromStream( - const Image *image) +static const void *GetVirtualMetacontentFromStream(const Image *image) { CacheInfo *cache_info; @@ -700,7 +699,7 @@ static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info, if (cache_info->pixels == (Quantum *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'", + ResourceLimitError,"MemoryAllocationFailed","'%s'", cache_info->filename); return(MagickFalse); } @@ -737,7 +736,7 @@ static const Quantum *GetVirtualPixelStream(const Image *image, (columns == 0) || (rows == 0)) { (void) ThrowMagickException(exception,GetMagickModule(),StreamError, - "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); + "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename); return((Quantum *) NULL); } cache_info=(CacheInfo *) image->cache; @@ -856,6 +855,9 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, CacheInfo *cache_info; + MagickBooleanType + status; + MagickSizeType number_pixels; @@ -875,14 +877,14 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, (columns == 0) || (rows == 0)) { (void) ThrowMagickException(exception,GetMagickModule(),StreamError, - "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename); + "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename); return((Quantum *) NULL); } stream_handler=GetBlobStreamHandler(image); if (stream_handler == (StreamHandler) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),StreamError, - "NoStreamHandlerIsDefined","`%s'",image->filename); + "NoStreamHandlerIsDefined","'%s'",image->filename); return((Quantum *) NULL); } cache_info=(CacheInfo *) image->cache; @@ -906,22 +908,32 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x, cache_info->rows=rows; number_pixels=(MagickSizeType) columns*rows; length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum); + if (length == 0) + length=number_pixels*sizeof(Quantum); if (cache_info->metacontent_extent != 0) length+=number_pixels*cache_info->metacontent_extent; if (cache_info->pixels == (Quantum *) NULL) { - cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,length); - cache_info->length=(MagickSizeType) length; + cache_info->length=length; + status=AcquireStreamPixels(cache_info,exception); + if (status == MagickFalse) + { + cache_info->length=0; + return((Quantum *) NULL); + } } else - if (cache_info->length < (MagickSizeType) length) + if (cache_info->length < length) { - (void) RelinquishAlignedMemory(cache_info->pixels); - cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,length); - cache_info->length=(MagickSizeType) length; + RelinquishStreamPixels(cache_info); + cache_info->length=length; + status=AcquireStreamPixels(cache_info,exception); + if (status == MagickFalse) + { + cache_info->length=0; + return((Quantum *) NULL); + } } - if (cache_info->pixels == (void *) NULL) - return((Quantum *) NULL); cache_info->metacontent=(void *) NULL; if (cache_info->metacontent_extent != 0) cache_info->metacontent=(void *) (cache_info->pixels+number_pixels* @@ -1178,8 +1190,7 @@ static size_t WriteStreamImage(const Image *image,const void *pixels, Prepare stream for writing. */ (void) RelinquishAlignedMemory(stream_info->pixels); - stream_info->pixels=(unsigned char *) AcquireAlignedMemory(length, - sizeof(*stream_info->pixels)); + stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length); if (stream_info->pixels == (unsigned char *) NULL) return(0); (void) ResetMagickMemory(stream_info->pixels,0,length); @@ -1312,7 +1323,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, if (quantum_map == (QuantumType *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); + ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename); return(MagickFalse); } for (i=0; i < (ssize_t) length; i++) @@ -1339,7 +1350,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, break; quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),ImageError, - "ColorSeparatedImageRequired","`%s'",stream_info->map); + "ColorSeparatedImageRequired","'%s'",stream_info->map); return(MagickFalse); } case 'g': @@ -1362,7 +1373,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, break; quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),ImageError, - "ColorSeparatedImageRequired","`%s'",stream_info->map); + "ColorSeparatedImageRequired","'%s'",stream_info->map); return(MagickFalse); } case 'M': @@ -1373,7 +1384,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, break; quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),ImageError, - "ColorSeparatedImageRequired","`%s'",stream_info->map); + "ColorSeparatedImageRequired","'%s'",stream_info->map); return(MagickFalse); } case 'o': @@ -1402,14 +1413,14 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, break; quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),ImageError, - "ColorSeparatedImageRequired","`%s'",stream_info->map); + "ColorSeparatedImageRequired","'%s'",stream_info->map); return(MagickFalse); } default: { quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),OptionError, - "UnrecognizedPixelMap","`%s'",stream_info->map); + "UnrecognizedPixelMap","'%s'",stream_info->map); return(MagickFalse); } } @@ -2629,7 +2640,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info, { quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); (void) ThrowMagickException(exception,GetMagickModule(),OptionError, - "UnrecognizedPixelMap","`%s'",stream_info->map); + "UnrecognizedPixelMap","'%s'",stream_info->map); break; } } @@ -2685,7 +2696,7 @@ static MagickBooleanType SyncAuthenticPixelsStream(Image *image, if (stream_handler == (StreamHandler) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),StreamError, - "NoStreamHandlerIsDefined","`%s'",image->filename); + "NoStreamHandlerIsDefined","'%s'",image->filename); return(MagickFalse); } length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns); -- 2.40.0