Skip to content

out of memory when processing this GIF #2402

Description

@mohanson

source: http://lavender.b0.upaiyun.com/ex.gif

example.jpg

import PIL
import PIL.Image

im = PIL.Image.open('example.gif')
print(im.size)
print(im.n_frames)  # will crash
[root /tmp] python3 run.py 
(320, 240)
Killed

The problem appear on this line https://github.com/python-pillow/Pillow/blob/master/PIL/GifImagePlugin.py#L261, self.dispose_extent is very huge.

env: python3.5 on linux, free mem is 2G.

thanks.

Activity

  1. mohanson commented on Feb 17, 2017

    @mohanson
    Author

    any idea?

  2. wiredfool commented on Feb 17, 2017

    @wiredfool
    Member

    Well, as you've noted, the dispose_extent of frame 90 is rather large:

    (Pdb) self.dispose_extent
    (37042, 49425, 90174, 109354)
    (Pdb) frame
    90
    

    This is fed to crop, which ultimately returns a new image. Or, tries to, as that's a rather large image.

    Any potential fix for #2383 could interact badly with this, as the dispose_extent winds up being the tile extents as well.

    Crop should really have the DecompressionBomb warning applied, as it can increase the size of the image. But in this case, we're calling into the core image object crop, not Image.crop, so we'd need to either hoist it to a python level function or call the decompression_bomb_check from the C layer.

  3. added
    BugAny unexpected behavior, until confirmed feature.
    on Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.GIF

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions