From: Dirk Lemstra Date: Thu, 18 Jan 2018 19:46:10 +0000 (+0100) Subject: Fixed memory leak. X-Git-Tag: 7.0.7-22~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92f20458181aece05d2a10845f77e50a0c8d9c2f;p=imagemagick Fixed memory leak. Credit to OSS-Fuzz --- diff --git a/coders/xcf.c b/coders/xcf.c index 6dd43348d..ead1e6ed1 100644 --- a/coders/xcf.c +++ b/coders/xcf.c @@ -1341,11 +1341,13 @@ static Image *ReadXCFImage(const ImageInfo *image_info,ExceptionInfo *exception) */ saved_pos=TellBlob(image); /* seek to the layer offset */ - if (SeekBlob(image,offset,SEEK_SET) != offset) - ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); - /* read in the layer */ - layer_ok=ReadOneLayer(image_info,image,&doc_info, - &layer_info[current_layer],current_layer,exception); + layer_ok=MagickFalse; + if (SeekBlob(image,offset,SEEK_SET) == offset) + { + /* read in the layer */ + layer_ok=ReadOneLayer(image_info,image,&doc_info, + &layer_info[current_layer],current_layer,exception); + } if (layer_ok == MagickFalse) { ssize_t j; @@ -1354,7 +1356,7 @@ static Image *ReadXCFImage(const ImageInfo *image_info,ExceptionInfo *exception) if (layer_info[j].image != (Image *) NULL) layer_info[j].image=DestroyImage(layer_info[j].image); layer_info=(XCFLayerInfo *) RelinquishMagickMemory(layer_info); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); } /* restore the saved position so we'll be ready to * read the next offset.