]> granicus.if.org Git - imagemagick/commitdiff
SetGrayscaleImage() no longer under allocates the color buffer
authorCristy <urban-warrior@imagemagick.org>
Sat, 20 Jan 2018 23:50:10 +0000 (18:50 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sat, 20 Jan 2018 23:50:10 +0000 (18:50 -0500)
Credit OSS Fuzz

MagickCore/quantize.c

index ca27477176da537790ec0abde88b5cbb2c4534e9..56903d33959f6e4852b178a30a504928e26134db 100644 (file)
@@ -3318,8 +3318,12 @@ static MagickBooleanType SetGrayscaleImage(Image *image,
   assert(image->signature == MagickCoreSignature);
   if (image->type != GrayscaleType)
     (void) TransformImageColorspace(image,GRAYColorspace,exception);
-  colormap_index=(ssize_t *) AcquireQuantumMemory(MaxColormapSize,
-    sizeof(*colormap_index));
+  if (image->storage_class == PseudoClass)
+    colormap_index=(ssize_t *) AcquireQuantumMemory(image->colors,
+      sizeof(*colormap_index));
+  else
+    colormap_index=(ssize_t *) AcquireQuantumMemory(MaxColormapSize,
+      sizeof(*colormap_index));
   if (colormap_index == (ssize_t *) NULL)
     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
       image->filename);