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

memory leak in ReadBGRImage #1041

Closed
bestshow opened this issue Mar 24, 2018 · 1 comment
Closed

memory leak in ReadBGRImage #1041

bestshow opened this issue Mar 24, 2018 · 1 comment
Labels

Comments

@bestshow
Copy link

Version: ImageMagick 7.0.7-28
Here is the critical code in function ReadBGRImage:

canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,        //160
    exception);
  if (canvas_image == (Image *) NULL)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
  (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
    exception);
  quantum_info=AcquireQuantumInfo(image_info,canvas_image);                    //166
  if (quantum_info == (QuantumInfo *) NULL)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 
  quantum_type=BGRQuantum;
  if (LocaleCompare(image_info->magick,"BGRA") == 0)
    {
      quantum_type=BGRAQuantum;
      image->alpha_trait=BlendPixelTrait;
      canvas_image->alpha_trait=BlendPixelTrait;
    }
  if (LocaleCompare(image_info->magick,"BGRO") == 0)
    {
      quantum_type=BGROQuantum;
      image->alpha_trait=BlendPixelTrait;
      canvas_image->alpha_trait=BlendPixelTrait;
    }
  pixels=(const unsigned char *) NULL;
  if (image_info->number_scenes != 0)
    while (image->scene < image_info->scene)
    {
      /*
        Skip to next image.
      */
      image->scene++;
      length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
      for (y=0; y < (ssize_t) image->rows; y++)
      {
        pixels=(const unsigned char *) ReadBlobStream(image,length,
          GetQuantumPixels(quantum_info),&count);
        if (count != (ssize_t) length)
          break;
      }
    }
  count=0;
  length=0;
  scene=0;
  do
  {
    /*
      Read pixels to virtual canvas image then push to image.
    */
    if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))
        break;
    status=SetImageExtent(image,image->columns,image->rows,exception);
    if (status == MagickFalse)
      return(DestroyImageList(image));                                        //212 
    switch (image_info->interlace)

line 212 forgot to free “canvas_image" (line 160) and “quantum_info” (line 166), this may cause memory leak.
Credit : ADLab of Venustech

@dlemstra
Copy link
Member

Thanks for reporting this. Pushed some patches to resolve this and it also includes a couple other fixes.

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

2 participants