[Image-SIG] memoryError in FpxImageUploadPlugin.py

Alec Bennett wrybread at gmail.com
Sat Apr 16 00:23:37 CEST 2011


> i only care about JPG/PNG/GIF...
> is there any way do a fileformat-whitelist?

Seems almost too obvious to mention, but you could do something like:

fname = "something.jpg"

image_extensions = (".jpg", ".png", ".gif")

extension = os.path.splitext(fname)[1].lower()

if extension in image_extensions:

    print "its an image!"

    do_some_stuff(fname)





2011/4/15 Gábor Farkas <gabor at nekomancer.net>

> hi,
>
> we have a python webserver that handles files uploaded by the users.
> some of those files cause a MemoryError in PIL.
> (unfortunately i do not have such a file). as you can see, it happens
> in the FpxImagPlugin:
> (pil 1.1.7)
>
>   im = Image.open(original)
>  File "/usr/local/lib/python2.6/site-packages/PIL/Image.py", line 1976, in
> open
>   return factory(fp, filename)
>  File "/usr/local/lib/python2.6/site-packages/PIL/ImageFile.py", line
> 91, in __init__
>   self._open()
>  File "/usr/local/lib/python2.6/site-packages/PIL/FpxImagePlugin.py",
> line 61, in _open
>   self.ole = OleFileIO(self.fp)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 260, in __init__
>   self.open(filename)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 289, in open
>   self.loadfat(header)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 309, in loadfat
>   s = self.getsect(ix)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 324, in getsect
>   self.fp.seek(512 + self.sectorsize * sect)
> MemoryError
>
> any ideas what might cause this?
>
> alternatively, is there a way to tell PIL to only try to handle a
> given list of file-types?
> for example, in my cases, i only care about JPG/PNG/GIF... so i do not need
> PIL
> to try to find out if the file is in other formats.. is there any way
> do a fileformat-whitelist?
>
> thanks,
> gabor
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110415/9b3d9382/attachment.html>


More information about the Image-SIG mailing list