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

cpu exhaustion in WritePixelCachePixels #659

Closed
xcainiao opened this issue Aug 8, 2017 · 2 comments
Closed

cpu exhaustion in WritePixelCachePixels #659

xcainiao opened this issue Aug 8, 2017 · 2 comments
Labels

Comments

@xcainiao
Copy link

xcainiao commented Aug 8, 2017

Version: ImageMagick 7.0.6-6 Q16 i686 2017-08-08 http://www.imagemagick.org

./magick cpu-poc2 /dev/null

static MagickBooleanType WritePixelCachePixels(
CacheInfo *magick_restrict cache_info,NexusInfo *magick_restrict nexus_info,
ExceptionInfo *exception)
{
.....

        switch (cache_info->type)

{
case MemoryCache:
case MapCache:
{
register Quantum
*magick_restrict q;

  /*
    Write pixels to memory.
  */
  if ((cache_info->columns == nexus_info->region.width) &&
      (extent == (MagickSizeType) ((size_t) extent)))
    {
      length=extent;
      rows=1UL;
    }
  q=cache_info->pixels+offset*cache_info->number_channels;
  for (y=0; y < (ssize_t) rows; y++)
  {
    (void) memcpy(q,p,(size_t) length);
    p+=cache_info->number_channels*nexus_info->region.width;
    q+=cache_info->columns*cache_info->number_channels;
  }
  break;
}
case DiskCache:
{
  /*
    Write pixels to disk.
  */
  LockSemaphoreInfo(cache_info->file_semaphore);
  if (OpenPixelCacheOnDisk(cache_info,IOMode) == MagickFalse)
    {
      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
        cache_info->cache_filename);
      UnlockSemaphoreInfo(cache_info->file_semaphore);
      return(MagickFalse);
    }
  if ((cache_info->columns == nexus_info->region.width) &&
      (extent <= MagickMaxBufferExtent))
    {
      length=extent;
      rows=1UL;
    }
  for (y=0; y < (ssize_t) rows; y++)
  {
    count=WritePixelCacheRegion(cache_info,cache_info->offset+offset*
      cache_info->number_channels*sizeof(*p),length,(const unsigned char *)
      p);
    if (count != (MagickOffsetType) length)
      break;
    p+=cache_info->number_channels*nexus_info->region.width;
    offset+=cache_info->columns;
  }

       ..... 

}

poc: https://github.com/xcainiao/poc/blob/master/cpu-poc2

@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.

@fgeek
Copy link

fgeek commented Sep 1, 2017

Please use CVE-2017-12875 for this issue.

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