From: Cristy Date: Sat, 30 Sep 2017 14:45:38 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/810 X-Git-Tag: 7.0.7-5~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=995715098e38596b27c9dd1fa57b154e07ec99f6;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/810 --- diff --git a/coders/pdb.c b/coders/pdb.c index 0412f3b1e..0b7a02b01 100644 --- a/coders/pdb.c +++ b/coders/pdb.c @@ -836,18 +836,24 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image, pdb_image.width=(short) (16*(image->columns/16+1)); pdb_image.height=(short) image->rows; packets=((bits_per_pixel*image->columns+7)/8); + packet_size=(size_t) (image->depth > 8 ? 2 : 1); runlength=(unsigned char *) AcquireQuantumMemory(9UL*packets, image->rows*sizeof(*runlength)); - if (runlength == (unsigned char *) NULL) - ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); buffer=(unsigned char *) AcquireQuantumMemory(512,sizeof(*buffer)); - if (buffer == (unsigned char *) NULL) - ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); - packet_size=(size_t) (image->depth > 8 ? 2 : 1); scanline=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size* sizeof(*scanline)); - if (scanline == (unsigned char *) NULL) - ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); + if ((runlength == (unsigned char *) NULL) || + (buffer == (unsigned char *) NULL) || + (scanline == (unsigned char *) NULL)) + { + if (runlength != (unsigned char *) NULL) + runlength=(unsigned char *) RelinquishMagickMemory(runlength); + if (buffer != (unsigned char *) NULL) + buffer=(unsigned char *) RelinquishMagickMemory(buffer); + if (scanline != (unsigned char *) NULL) + scanline=(unsigned char *) RelinquishMagickMemory(scanline); + ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); + } if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) (void) TransformImageColorspace(image,sRGBColorspace,exception); /*