[Image-SIG] Bug in FPX handling (in OleFileIO.py)

Robert Bunting rjbunting at gmail.com
Sun Apr 29 09:51:49 CEST 2007


I'm not sure if it's been noted before, but there's an incompatility in PIL
with the FlashPix file IO and python 2.4 and up.  Trying to load such a file
can give OverflowError; see patch below.



In the file OleFileIO.py
, the function i32() uses <<.  Several parts of this file then rely on
the old behavior of this function to wrap round to negative values once the
input is past 0xFFFFFFFF (ie 1<<32 == 0)

Python 2.4 and up no longer does this, which means that the library fails to
spot the
end of header bytes, as it tests for == -1 and ==-2 (e.g. in loadfat()).

This can result in an OverflowError being thrown, which is a problem for me
when someone inputs an invalid file (I'm actually seeing this on MS word
files posted to a website as
images by mistake, but it could happen with a valid fpx file).

A simple way to get back to the previous correct behavior would be to patch
as follows:

diff OleFileIO.py.new OleFileIO.py
46c46,49
< def i32(c, o = 0):
<     return ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24)
---
> def i32(c, o = 0):
>     ival = ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24)
>     if ival > 0x80000000:
>         ival -= 0x100000000
>     return ival

but a good alternative would be to fix all the tests in the library.

I guess this part of the library doesn't get exercised much :)

BR,

Robert Bunting.
exoweb.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20070429/2d753d12/attachment.html 


More information about the Image-SIG mailing list