From: Cristy Date: Sun, 21 Jan 2018 16:54:59 +0000 (-0500) Subject: Eliminate assertion X-Git-Tag: 7.0.7-22~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b14912836d8f208c1f1f17929b64153b46e8d12f;p=imagemagick Eliminate assertion Credit OSS-FUZZ --- diff --git a/coders/wpg.c b/coders/wpg.c index 56f96d3df..058384208 100644 --- a/coders/wpg.c +++ b/coders/wpg.c @@ -768,7 +768,10 @@ static Image *ExtractPostscript(Image *image,const ImageInfo *image_info, (void) SeekBlob(image,PS_Offset,SEEK_SET); count=ReadBlob(image, 2*MagickPathExtent, magick); if (count < 1) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + { + DestroyImageInfo(clone_info); + ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + } (void) SeekBlob(image,PS_Offset,SEEK_SET); while (PS_Size-- > 0) @@ -1115,10 +1118,15 @@ static Image *ReadWPGImage(const ImageInfo *image_info, break; case 0x11: /* Start PS l1 */ - if(Rec.RecordLength > 8) - image=ExtractPostscript(image,image_info, - TellBlob(image)+8, /* skip PS header in the wpg */ - (ssize_t) Rec.RecordLength-8,exception); + if (Rec.RecordLength > 8) + { + image=ExtractPostscript(image,image_info, + TellBlob(image)+8, /* skip PS header in the wpg */ + (ssize_t) Rec.RecordLength-8,exception); + if (image == NULL) + ThrowReaderException(CorruptImageError, + "ImproperImageHeader"); + } break; case 0x14: /* bitmap type 2 */ @@ -1255,10 +1263,15 @@ static Image *ReadWPGImage(const ImageInfo *image_info, break; case 0x1B: /* Postscript l2 */ - if(Rec.RecordLength>0x3C) - image=ExtractPostscript(image,image_info, - TellBlob(image)+0x3C, /* skip PS l2 header in the wpg */ - (ssize_t) Rec.RecordLength-0x3C,exception); + if (Rec.RecordLength>0x3C) + { + image=ExtractPostscript(image,image_info, + TellBlob(image)+0x3C, /* skip PS l2 header in the wpg */ + (ssize_t) Rec.RecordLength-0x3C,exception); + if (image == NULL) + ThrowReaderException(CorruptImageError, + "ImproperImageHeader"); + } break; } } @@ -1446,10 +1459,15 @@ static Image *ReadWPGImage(const ImageInfo *image_info, case 0x12: /* Postscript WPG2*/ i=ReadBlobLSBShort(image); - if(Rec2.RecordLength > (unsigned int) i) - image=ExtractPostscript(image,image_info, - TellBlob(image)+i, /*skip PS header in the wpg2*/ - (ssize_t) (Rec2.RecordLength-i-2),exception); + if (Rec2.RecordLength > (unsigned int) i) + { + image=ExtractPostscript(image,image_info, + TellBlob(image)+i, /*skip PS header in the wpg2*/ + (ssize_t) (Rec2.RecordLength-i-2),exception); + if (image == NULL) + ThrowReaderException(CorruptImageError, + "ImproperImageHeader"); + } break; case 0x1B: /*bitmap rectangle*/