CVE-2017-9144 (Other, published 2017-05-22T14:29Z)
Description: value: In ImageMagick 7.0.5-5, a crafted RLE image can trigger a crash because of incorrect EOF handling in coders/rle.c.
Severity: MEDIUM (CVSS v3 base score: 6.5)
Weakness: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
Repository: https://github.com/ImageMagick/ImageMagick
Files changed:
ChangeLog
coders/rle.c
Commit message: Check for EOF conditions for RLE image format


Vulnerable code:
    image->page.x=ReadBlobLSBShort(image);
    image->page.y=ReadBlobLSBShort(image);
      {
        ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
          image->filename);
        break;
      }
    colormap=(unsigned char *) NULL;
      {
        ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
          image->filename);
        break;
      }
            operand=ReadBlobLSBSignedShort(image);
            operand=ReadBlobLSBSignedShort(image);
            operand=ReadBlobLSBSignedShort(image);
          offset=((image->rows-y-1)*image->columns*number_planes)+x*
            number_planes+plane;
              (offset+((size_t) operand*number_planes) > pixel_info_length))
            operand=ReadBlobLSBSignedShort(image);
          offset=((image->rows-y-1)*image->columns*number_planes)+x*
            number_planes+plane;
              (offset+((size_t) operand*number_planes) > pixel_info_length))
            ValidateColormapValue(image,*p & mask,&index,exception);
                ValidateColormapValue(image,(size_t) (x*map_length+
                SetPixelIndex(image,*p++,q);

Fixed code:
  * Check for EOF conditions for RLE image format.
#define ThrowRLEException(exception,message) \
{ \
  if (colormap != (unsigned char *) NULL) \
    colormap=(unsigned char *) RelinquishMagickMemory(colormap); \
  if (pixel_info != (MemoryInfo *) NULL) \
    pixel_info=RelinquishVirtualMemory(pixel_info); \
  ThrowReaderException((exception),(message)); \
}
  colormap=(unsigned char *) NULL;
  pixel_info=(MemoryInfo *) NULL;
    image->page.x=(ssize_t) ReadBlobLSBShort(image);
    image->page.y=(ssize_t) ReadBlobLSBShort(image);
    if (EOFBlob(image) != MagickFalse)
      ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
      ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
	  {
            if (EOFBlob(image) != MagickFalse)
              ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
	  }
      ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
    if (opcode == EOF)
      ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
          if (opcode == EOF)
            ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            {
              operand=ReadBlobLSBSignedShort(image);
              if (opcode == EOF)
                ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
	    }
          if (opcode == EOF)
            ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
          if (opcode == EOF)
            ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            {
              operand=ReadBlobLSBSignedShort(image);
              if (opcode == EOF)
                ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            }
          if (opcode == EOF)
            ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            {
              operand=ReadBlobLSBSignedShort(image);
              if (opcode == EOF)
                ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            }
          offset=(ssize_t) (((image->rows-y-1)*image->columns*number_planes)+x*
            number_planes+plane);
              ((offset+operand*number_planes) > (ssize_t) pixel_info_length))
          if (opcode == EOF)
            ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            {
              operand=ReadBlobLSBSignedShort(image);
              if (opcode == EOF)
                ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            }
          offset=(ssize_t) (((image->rows-y-1)*image->columns*number_planes)+x*
            number_planes+plane);
              ((offset+operand*number_planes) > (ssize_t) pixel_info_length))
      if (opcode == EOF)
        ThrowRLEException(CorruptImageError,"UnexpectedEndOfFile");
            ValidateColormapValue(image,(ssize_t) (*p & mask),&index,exception);
                ValidateColormapValue(image,(ssize_t) (x*map_length+
                SetPixelIndex(image,(Quantum) *p++,q);