Skip to content

image/gif: GIF encoder corrupts subimages #7792

Description

@ctrlsuper
What does 'go version' print?
go version devel +8e5787506b59 Tue Apr 15 15:52:23 2014 -0400 + linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Create an image in a GIF where the bounds of the Paletted image is different from the
backing pixel slice. For example, create an image using Paletted.SubImage() that is
narrower than the original image.
2. Attempt to encode this GIF.

Example (needs file access): http://play.golang.org/p/Ck6A7ih6Hv

What happened?
The frame created from the subimage looks corrupted (example in buggy.gif)

What should have happened instead?
The frame should look correct (example in fixed.gif)

Please provide any additional information below.
Looks like this is due to the "common mistake" described at
http://blog.golang.org/go-image-package#TOC_4. where it is assumed that the backing data
matches the dimensions of the image.

The encoder attempts to write the entire Px slice instead of respecting the image
bounds: http://golang.org/src/pkg/image/gif/writer.go?s=5197:5226#L236

The attached patch appears to fix it. I'd be happy to make a CL once I figure out the
review tools.

Attachments:

  1. buggy.gif (26883 bytes)
  2. fixed.gif (17539 bytes)
  3. gif_writer_subimage.patch (508 bytes)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions