[Image-SIG] Re: PIL Bug: Crash processing GIF image

Fredrik Lundh fredrik at pythonware.com
Fri Feb 20 12:17:25 EST 2004


Chris Cogdon wrote:

> I've had cause to run my PIL-based thumbnailing code over the vast
> collection of artwork from my community artwork site, and I've
> encountered one image that causes PIL/Python to behave very badly. When
> doing a 'convert', python will  report a quantization error (if it gets
> that far)... but it is also accompanied by either a CPU lock-up, or a
> segmentation fault, which makes trapping for exceptions a little tricky
> :)
>
> I've tried it with PIL 1.1.3 and 1.1.4 with the same effect, but there
> are some system combinations where it actually does not crash, and
> instead only reports the quantization error.

it looks like the GIF codec messes up when it's trying to determine
the right size of the file, which results in a 62004-pixel high image
memory, which results in a 0-pixel wide thumbnail, which causes the
quantization code to mess up.

> I'm reporting the bug here, as suggested by the pythonware people... if
> you (pythonware) can peek at it, that would be fantastic :) in the
> meantime, I'll just mark that file as 'poison' to my code.

a workaround is to check the height/width ratio.  something like
this might work (untested):

    i = Image.open(...)

    w, h = i.size

    if w > h*50 or h > w*50:
        print "your image file doesn't look right; it's probably a"
        print "bug on our side, but while you're waiting for us to"
        print "fix it, you could try converting it to another file"
        print "format and uploading it again."
    else:
        ...

</F>






More information about the Image-SIG mailing list