Menu

#761 Reading multiple GIFs doesn't read the comments correctly.

v1.0_(example)
closed-fixed
gif (3)
5
2025-11-23
2025-11-23
No

In the GIF file, the comment is before the pixel data. The existing code in 1.3.46 reads comment and assigns it to the last frame. But it needs to store comment and assign it to the next frame.

Discussion

  • Christian Schmitz

    To fix this, I made comments a variable before the loop:

      char
        *comments = (char *) NULL;
    

    then when reading the comment, we just store it:

    comments=comments_new;
    

    later when we read the GIF frame, we add the comment:

        if (comments)
          {
            (void) SetImageAttribute(image,"comment",comments);
            MagickFreeResourceLimitedMemory(comments);
            comments = NULL;
          }
    

    and on the end, we need to free comments, if it is still there

      if (comments)
        {
          (void) SetImageAttribute(image,"comment",comments);
          MagickFreeResourceLimitedMemory(comments);
        }
    

    Attached my copy of the gif.c file with the fix. You may just compare to yours and move over the fix, if you think this is a good fix. Thanks.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-23
    • status: open --> closed-fixed
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-23

    This issue should be addressed by Mercurial changeset 17869:67f0e477d45e. Thanks for reporting this issue and providing an example.

     
  • Christian Schmitz

    Thank you. That was quick!

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2025-11-23

    Please verify that you are pleased with the result.

     
  • Christian Schmitz

    Looks like you didn't fix it for multi frame images. Or did I misunderstand the code?

    if (comments)
        {
          (void) SetImageAttribute(image,"comment",NULL);
          (void) SetImageAttribute(image,"comment",comments);
        }
    

    this block is on the bottom. But this must go up to where the image is read.

    The key thing is that we have a GIF with 8 frames. Each frame has a comment.
    So we have 8 comments and 8 images and I think we need to read each image comment.
    since not each image has a comment, you also need to set comments to NULL.

    Please compare to my code, which definitively can read 8 comments for 8 GIF frames.

     

Log in to post a comment.

MongoDB Logo MongoDB