From dbc1e15ebc8e9bc4ff4a17cf603ba1ccecf477e3 Mon Sep 17 00:00:00 2001 From: Cristy Date: Wed, 26 Apr 2017 17:16:56 -0400 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/449 --- coders/sun.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/coders/sun.c b/coders/sun.c index c3d87dc45..c10562f67 100644 --- a/coders/sun.c +++ b/coders/sun.c @@ -363,19 +363,28 @@ static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); count=ReadBlob(image,image->colors,sun_colormap); if (count != (ssize_t) image->colors) - ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + { + sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap); + ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + } for (i=0; i < (ssize_t) image->colors; i++) image->colormap[i].red=(MagickRealType) ScaleCharToQuantum( sun_colormap[i]); count=ReadBlob(image,image->colors,sun_colormap); if (count != (ssize_t) image->colors) - ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + { + sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap); + ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + } for (i=0; i < (ssize_t) image->colors; i++) image->colormap[i].green=(MagickRealType) ScaleCharToQuantum( sun_colormap[i]); count=ReadBlob(image,image->colors,sun_colormap); if (count != (ssize_t) image->colors) - ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + { + sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap); + ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); + } for (i=0; i < (ssize_t) image->colors; i++) image->colormap[i].blue=(MagickRealType) ScaleCharToQuantum( sun_colormap[i]); @@ -395,9 +404,9 @@ static Image *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception) if (sun_colormap == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); count=ReadBlob(image,sun_info.maplength,sun_colormap); + sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap); if (count != (ssize_t) sun_info.maplength) ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); - sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap); break; } default: -- 2.50.1