Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

large loop in ReadPWPImage with no meaning #535

Closed
jgj212 opened this issue Jul 4, 2017 · 2 comments
Closed

large loop in ReadPWPImage with no meaning #535

jgj212 opened this issue Jul 4, 2017 · 2 comments
Labels

Comments

@jgj212
Copy link
Contributor

jgj212 commented Jul 4, 2017

Version: ImageMagick 7.0.6-1 Q16 x86_64

$magick identify $FILE

Here is the critical code

    filesize=65535UL*magick[2]+256L*magick[1]+magick[0];     // filesize can be controlled
    for (i=0; i < (ssize_t) filesize; i++)                   
    {
      c=ReadBlobByte(pwp_image);
      (void) fputc(c,file);
    }

magick[...] is from ReadBlobByte

    for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image))
    {
      for (i=0; i < 17; i++)
        magick[i]=magick[i+1];
      magick[17]=(unsigned char) c;
      if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0)
        break;
    }

magick[x] can be large as 0xff:

  unsigned char
    magick[MagickPathExtent];

So 'filesize' can be large as 65535UL*255 = 1600w, the loop in the above will be large.
On the other handle, 'ReadBlobByte' in the loop has no success_status checking, so a crafted file will cause a larget of failed I/O in the loop.

testcase:
https://github.com/jgj212/poc/blob/master/cpu-ReadPWPImage

Credit: ADLab of Venustech

@jgj212 jgj212 changed the title CPU exhaustion in ReadPWPImage large loop in ReadPWPImage with no meaning Jul 4, 2017
@mikayla-grace
Copy link

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.

@nohmask
Copy link

nohmask commented Sep 8, 2017

This was assigned CVE-2017-12587.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants