From 995715098e38596b27c9dd1fa57b154e07ec99f6 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 30 Sep 2017 10:45:38 -0400 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/810 --- coders/pdb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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); /* -- 2.40.0