PIL fails when trying to parse a streaming png file

Issue #4 resolved
gordallott
created an issue

PIL 1.1.6-3ubuntu1 fails when operating on an png file from its parser() method with {{{ Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 961, in histogram self.load() File "/usr/lib/python2.6/dist-packages/PIL/ImageFile.py", line 189, in load s = read(self.decodermaxblock) File "/usr/lib/python2.6/dist-packages/PIL/PngImagePlugin.py", line 365, in load_read return self.fp.read(bytes) File "/usr/lib/python2.6/dist-packages/PIL/ImageFile.py", line 300, in read data = self.data[pos:pos+bytes] TypeError: 'NoneType' object is unsubscriptable }}} this python script will expose the bug: {{{

!/usr/bin/env python

import PIL.ImageFile imgfile = open('foo.png') p = PIL.ImageFile.Parser()

while 1: data = imgfile.read(1024) if not data: break p.feed(data)

img = p.close() img.histogram() # simple operation on PIL.Image object, should work but fails on png files }}}

Attached is a patch that fixes this, a lack of any bug tracker/development contact for python-imaging upstream necessitates it being here.

Comments (1)

  1. Log in to comment