Skip to content

memory leak bug in meta.c: parse8BIM() function #1190

Closed
@fisher2020

Description

@fisher2020

Prerequisites

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

Description

hello,i find a memory leak bug in imagemagick,the details is on the Steps to Reproduce.

Steps to Reproduce

the bug located in meta.c ,static ssize_t parse8BIM(Image *ifile, Image *ofile) function
the bug code is on
https://github.com/ImageMagick/ImageMagick/blob/master/coders/meta.c#L327
the code fragment is as follows:

  line = (char *) AcquireQuantumMemory((size_t) inputlen,sizeof(*line)); //llocate a memory and assigned it to line
  if (line == (char *) NULL)
    return(-1);
  newstr = name = token = (char *) NULL;
  savedpos = 0;
  token_info=AcquireTokenInfo();

we can see that we allocate a memory and assigned it to line,but we forget to free it in the code:
https://github.com/ImageMagick/ImageMagick/blob/master/coders/meta.c#L436
the code is as follows:

                if (savedolen > 0)
                  {
                    MagickOffsetType
                      offset;

                    ssize_t diff = outputlen - savedolen;
                    currentpos = TellBlob(ofile);
                    if (currentpos < 0)
                      return(-1);   // return without free line pointed memory
                    offset=SeekBlob(ofile,savedpos,SEEK_SET);
                    if (offset < 0)
                      return(-1);  // return without free line pointed memory
                    (void) WriteBlobMSBLong(ofile,(unsigned int) diff);
                    offset=SeekBlob(ofile,currentpos,SEEK_SET);
                    if (offset < 0)
                      return(-1);
                    savedolen = 0L;
                  }

credit:www.vackbot.com(墨云科技)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions