From 36e2aabfdef4603f5011d7df45fa470c4e509c62 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 5 Nov 2017 08:10:05 -0500 Subject: [PATCH] ... --- coders/sfw.c | 5 ++++- coders/wpg.c | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/coders/sfw.c b/coders/sfw.c index f9a140265..5f526e5ea 100644 --- a/coders/sfw.c +++ b/coders/sfw.c @@ -252,6 +252,8 @@ static Image *ReadSFWImage(const ImageInfo *image_info,ExceptionInfo *exception) */ if (GetBlobSize(image) != (size_t) GetBlobSize(image)) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + if (GetBlobSize(image) < 141) + ThrowReaderException(CorruptImageError,"ImproperImageHeader"); buffer=(unsigned char *) AcquireQuantumMemory((size_t) GetBlobSize(image)+ MagickPathExtent,sizeof(*buffer)); if (buffer == (unsigned char *) NULL) @@ -269,7 +271,8 @@ static Image *ReadSFWImage(const ImageInfo *image_info,ExceptionInfo *exception) */ header=SFWScan(buffer,buffer+count-1,(const unsigned char *) "\377\310\377\320",4); - if (header == (unsigned char *) NULL) + if ((header == (unsigned char *) NULL) || + ((header+140) > (buffer+GetBlobSize(image)))) { buffer=(unsigned char *) RelinquishMagickMemory(buffer); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); diff --git a/coders/wpg.c b/coders/wpg.c index 33c8b25a9..02987790c 100644 --- a/coders/wpg.c +++ b/coders/wpg.c @@ -501,7 +501,11 @@ static int UnpackWPGRaster(Image *image,int bpp,ExceptionInfo *exception) BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff); return(-4); } - InsertRow(image,BImgBuff,y-1,bpp,exception); + if (InsertRow(image,BImgBuff,y-1,bpp,exception) == MagickFalse) + { + BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff); + return(-5); + } } } } @@ -1110,7 +1114,7 @@ static Image *ReadWPGImage(const ImageInfo *image_info, status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) break; - if ((image->colors == 0) && (bpp <= 16)) + if ((image->storage_class != PseudoClass) && (bpp != 24)) { image->colors=one << bpp; if (!AcquireImageColormap(image,image->colors,exception)) @@ -1331,11 +1335,16 @@ static Image *ReadWPGImage(const ImageInfo *image_info, if (BImgBuff == (unsigned char *) NULL) goto NoMemory; - for(i=0; i< (ssize_t) image->rows; i++) - { - (void) ReadBlob(image,ldblk,BImgBuff); - InsertRow(image,BImgBuff,i,bpp,exception); - } + for (i=0; i< (ssize_t) image->rows; i++) + { + (void) ReadBlob(image,ldblk,BImgBuff); + if (InsertRow(image,BImgBuff,i,bpp,exception) == MagickFalse) + { + if(BImgBuff) + BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff); + goto DecompressionFailed; + } + } if(BImgBuff) BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff); -- 2.40.0