Fredrik Lundh is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

effbot / pil-2009-raclette http://effbot.org/zone/pil-index.htm

Work repository for PIL 1.1.7 and beyond. The "default" branch should be fairly solid, the other branches less so. For production use, see the pil-117 repository.

Clone this repository (size: 1.6 MB): HTTPS / SSH
hg clone https://bitbucket.org/effbot/pil-2009-raclette
hg clone ssh://hg@bitbucket.org/effbot/pil-2009-raclette

Issues

#4 PIL fails when trying to parse a streaming png file

Reported by gordallott

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.

Status: resolved Responsible: Fredrik Lundh Type: bug Priority: major
Milestone: raclette-alpha Component: pil-core Version: pil-1.1.6

Attachments

Comments and changes

  1. #1 Fredrik Lundh

    written

    • Changed status from new to resolved.

    Fixed in fe4688f15fed .

Add comment / attachment

Verification: Please write the text from the image in the box (letters only)

captcha

Is that you, Humanoid? Is this me?