[Image-SIG] OverflowError on image save

Wichert Akkerman wichert at simplon.biz
Tue Mar 3 22:21:05 CET 2009


I have a small routine which tries to verify if an uploaded file is a 
valid image. It works like this:

         image_data=StringIO(data)
         try:
             pil_data=PIL.Image.open(image_data)
         except IOError: # PIL abuses IOError to report parsing errors
             raise Invalid(self.message("bad_image", state),
                     value, state)

         pil_data.load()
         (width,height)=pil_data.size


For some images I get an OverflowError on the load() call:

ModulePIL.ImageFile:*155*  in|load|
>>     <imap://wichert%40simplon%2Ebiz@mx1.simplon.biz:993/fetch%3EUID%3E.2style4you.Site%20Errors%3E331#>self.load_prepare()
ModulePIL.ImageFile:*223*  in|load_prepare|
>>     <imap://wichert%40simplon%2Ebiz@mx1.simplon.biz:993/fetch%3EUID%3E.2style4you.Site%20Errors%3E331#>self.im  =  Image.core.new(self.mode,  self.size)*
OverflowError: long int too large to convert to int
*

I can not find any information as to what the problem might be. It seems 
to only occur for bmp files; jpeg and png appear to work correctly.

This is using PIL 1.1.6 and Python 2.5 on a Linux system.

Wichert.
<< 
<imap://wichert%40simplon%2Ebiz@mx1.simplon.biz:993/fetch%3EUID%3E.2style4you.Site%20Errors%3E331#> 
self.map = None

self.load_prepare()

# look for read/seek overrides
<< 
<imap://wichert%40simplon%2Ebiz@mx1.simplon.biz:993/fetch%3EUID%3E.2style4you.Site%20Errors%3E331#> 
if not self.im or\
self.im.mode != self.mode or self.im.size != self.size:
self.im = Image.core.new(self.mode, self.size)
# create palette (optional)
if self.mode == "P":
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090303/b66f827b/attachment.htm>


More information about the Image-SIG mailing list