CVE-2016-4563 (Other, published 2016-06-04T16:59Z)
Description: value: The TraceStrokePolygon function in MagickCore/draw.c in ImageMagick before 6.9.4-0 and 7.x before 7.0.1-2 mishandles the relationship between the BezierQuantum value and certain strokes data, which allows remote attackers to cause a denial of service (buffer overflow and application crash) or possibly have unspecified other impact via a crafted file.
Severity: MEDIUM (CVSS v3 base score: 8.8)
Weakness: CWE-119 \u2014 Improper Restriction of Operations within the Bounds of a Memory Buffer
The product performs operations on a memory buffer, but it reads from or writes to a memory location outside the buffer's intended boundary. This may result in read or write operations on unexpected memory locations that could be linked to other variables, data structures, or internal program data.
Repository: https://github.com/ImageMagick/ImageMagick
Files changed:
ChangeLog
MagickCore/draw.c
Commit message: Prevent buffer overflow in magick/draw.c


Vulnerable code:
  clip_mask->background_color.alpha=(Quantum) TransparentAlpha;
  for (i=1; (i < number_vertices) && (length >= 0.0); i++)
    GetNextToken(q,&q,extent,keyword);
              weight=StringToUnsignedLong(token);
                (void) FormatLocaleString(key,MagickPathExtent,"%s-geometry",name);
          clone_info->stroke.alpha=(Quantum) TransparentAlpha;
          clone_info->stroke.alpha=(Quantum) TransparentAlpha;
  clone_info->stroke.alpha=(Quantum) TransparentAlpha;
  draw_info->undercolor.alpha=(Quantum) TransparentAlpha;
        weight=StringToUnsignedLong(option);
         max_strokes+=6*BezierQuantum+360;
         path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes,
           sizeof(*path_p));
         path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes,
           sizeof(*path_q));
         if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
           {
             polygon_primitive=(PrimitiveInfo *)
               RelinquishMagickMemory(polygon_primitive);
             return((PrimitiveInfo *) NULL);
           }

Fixed code:
2016-05-04  7.0.1-2 Cristy  <quetzlzacatenango@image...>
  * Check for buffer overflow in magick/draw.c/DrawStrokePolygon().

  clip_mask->background_color.alpha=(MagickRealType) TransparentAlpha;
  for (i=1; (i < (ssize_t) number_vertices) && (length >= 0.0); i++)
    GetNextToken(q,&q,MagickPathExtent,keyword);
              weight=(ssize_t) StringToUnsignedLong(token);
                (void) FormatLocaleString(key,MagickPathExtent,"%s-geometry",
                  name);
          clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
          clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
  clone_info->stroke.alpha=(MagickRealType) TransparentAlpha;
  draw_info->undercolor.alpha=(MagickRealType) TransparentAlpha;
        weight=(ssize_t) StringToUnsignedLong(option);
        if (~max_strokes < (6*BezierQuantum+360))
          {
            path_p=(PointInfo *) RelinquishMagickMemory(path_p);
            path_q=(PointInfo *) RelinquishMagickMemory(path_q);
          }
        else
          {
            max_strokes+=6*BezierQuantum+360;
            path_p=(PointInfo *) ResizeQuantumMemory(path_p,max_strokes,
              sizeof(*path_p));
            path_q=(PointInfo *) ResizeQuantumMemory(path_q,max_strokes,
              sizeof(*path_q));
          }
        if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL))
          {
            if (path_p != (PointInfo *) NULL)
              path_p=(PointInfo *) RelinquishMagickMemory(path_p);
            if (path_q != (PointInfo *) NULL)
              path_q=(PointInfo *) RelinquishMagickMemory(path_q);
            polygon_primitive=(PrimitiveInfo *)
              RelinquishMagickMemory(polygon_primitive);
            return((PrimitiveInfo *) NULL);
          }