[Image-SIG] OverflowError on image save
Wichert Akkerman
wichert at simplon.biz
Sun Mar 8 18:09:13 CET 2009
I sent two images demonstrating the problem to Fredrik off-list.
I suspect this is a fairly common problem: I have seen this error occur
several when users try to upload a member portrait to a community site,
and at this moment only a handful users have access to it since it is
still in a closed test phase.
Wichert.
On 3/6/09 5:43 PM, Fredrik Lundh wrote:
> Does anyone have a (preferrably) small example, or a simple way to
> create a broken file on a stock Windows XP machine? An URL or an
> off-list mail works fine.
>
> </F>
>
> On Fri, Mar 6, 2009 at 4:52 PM, Howard Lightstone
> <howard at eegsoftware.com> wrote:
>
>> This LOOKS like a bug in Windows XP which creates .BMP files via DirectX
>> with an incorrect bitmap header size (54 vice 40). Changing the 54 to 40
>> makes the file readable again. Most utilities seem to ignore this but
>> Windows itself won't be able to 'read' it as a .BMP file.
>>
>> (using XP SP2 and DirectX 9.0c ... I haven't tried this on Vista yet)
>>
>> On Fri, Mar 6, 2009 at 5:50 AM, Wichert Akkerman<wichert at simplon.biz>
>> wrote:
>>
>>> The first image:
>>>
>>>
>>>>>> i=PIL.Image.open(open("/Users/wichert/Desktop/dont.bmp"))
>>>>>> i
>>>>>>
>>> <PIL.BmpImagePlugin.BmpImageFile instance at 0x43f490>
>>>
>>>>>> i.mode
>>>>>>
>>> 'RGB'
>>>
>>>>>> i.size
>>>>>>
>>> (290, 4294967075L)
>>>
>>>>>> i.tile
>>>>>>
>>> [('raw', (0, 0, 290, 4294967075L), 54, ('BGR', 872, -1))]
>>>
>>> and the second image:
>>>
>>>
>>>>>> i=PIL.Image.open(open("/Users/wichert/Desktop/dont2.bmp"))
>>>>>> i.mode
>>>>>>
>>> 'RGB'
>>>
>>>>>> i.size
>>>>>>
>>> (288, 4294967078L)
>>>
>>>>>> i.tile
>>>>>>
>>> [('raw', (0, 0, 288, 4294967078L), 54, ('BGR', 864, -1))]
>>>
>>>
>>> Regards,
>>> Wichert.
>>>
>>> On 3/5/09 6:41 PM, Fredrik Lundh wrote:
>>>
>>>> Can you print the following attributes for a broken file, before calling
>>>> load:
>>>>
>>>> pil_data.mode
>>>> pil_data.size
>>>> pil_data.tile
>>>>
>>>> </F>
>>>>
>>>> 2009/3/3 Wichert Akkerman<wichert at simplon.biz>:
>>>>
>>>>
>>>>> 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:
>>>>>
>>>>> Module PIL.ImageFile:155 in load
>>>>>
>>>>>
>>>>>>> self.load_prepare()
>>>>>>>
>>>>>>>
>>>>> Module PIL.ImageFile:223 in load_prepare
>>>>>
>>>>>
>>>>>>> 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.
>>>>> << self.map = None
>>>>>
>>>>> self.load_prepare()
>>>>>
>>>>> # look for read/seek overrides
>>>>> << 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":
>>>>> _______________________________________________
>>>>> Image-SIG maillist - Image-SIG at python.org
>>>>> http://mail.python.org/mailman/listinfo/image-sig
>>>>>
>>>>>
>>>>>
>>>>>
>>> _______________________________________________
>>> Image-SIG maillist - Image-SIG at python.org
>>> http://mail.python.org/mailman/listinfo/image-sig
>>>
>>>
>>
>> --
>> Howard Lightstone
>> hlightstone at gmail.com
>> howard at eegsoftware.com
>>
>>
More information about the Image-SIG
mailing list