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

There is a potential memory leak in codes/tiff.c #1206

Closed
Young-X opened this issue Jul 12, 2018 · 2 comments
Closed

There is a potential memory leak in codes/tiff.c #1206

Young-X opened this issue Jul 12, 2018 · 2 comments
Labels

Comments

@Young-X
Copy link

Young-X commented Jul 12, 2018

Prerequisites

  • [ Y ] I have written a descriptive issue title
  • [ Y ] I have verified that I am using the latest version of ImageMagick
  • [ Y ] I have searched open and closed issues to ensure it has not already been reported

Description

There is a potential memory leak vulnerability in TIFFWritePhotoshopLayers function in coders/tiff.c.

Steps to Reproduce

As we can see, there is a check for base_image equals to NULL or not in line 3123. (https://github.com/ImageMagick/ImageMagick/blob/master/coders/tiff.c#L3123)
At the same time, there are several call to ThrowBinaryException in line 3127, line 3135, line 3145 and line 3154. I think base_image should be destroyed firstly before call ThrowBinaryException. Otherwise, there would be a memory leak vulnerability.

3122  base_image=CloneImage(image,0,0,MagickFalse,exception);
3123  if (base_image == (Image *) NULL)
3124    return(MagickTrue);
3125  clone_info=CloneImageInfo(image_info);
3126  if (clone_info == (ImageInfo *) NULL)
3127    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3128      image->filename);
3129  profile.offset=0;
3130  profile.quantum=MagickMinBlobExtent;
3131  layers=AcquireStringInfo(profile.quantum);
3132  if (layers == (StringInfo *) NULL)
3133    {
3134      clone_info=DestroyImageInfo(clone_info);
3135      ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3136        image->filename);
3137    }
3138  profile.data=layers;
3139  profile.extent=layers->length;
3140  custom_stream=TIFFAcquireCustomStreamForWriting(&profile,exception);
3141  if (custom_stream == (CustomStreamInfo *) NULL)
3142    {
3143      clone_info=DestroyImageInfo(clone_info);
3144      layers=DestroyStringInfo(layers);
3145      ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3146        image->filename);
3147    }
3148  blob=CloneBlobInfo((BlobInfo *) NULL);
3149  if (blob == (BlobInfo *) NULL)
3150    {
3151      clone_info=DestroyImageInfo(clone_info);
3152      layers=DestroyStringInfo(layers);
3153      custom_stream=DestroyCustomStreamInfo(custom_stream);
3154      ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
3155        image->filename);
3156    }

System Configuration

  • ImageMagick version: latest version
  • Environment (Operating system, version and so on):
  • Additional information:
@dlemstra
Copy link
Member

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 7, 2018

This was assigned CVE-2018-16641.

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

3 participants