[reportlab-users] _digester

Dirk Holtwick dirk.holtwick at gmail.com
Mon Mar 30 03:47:13 EDT 2009


Hi,

I had a nasty bug for some time in Pisa <http://www.xhtml2pdf.com>
regarding images. Finally I found out that this was originally a bug in
Reportlab and therefore I would like to let you know.

The problem seems to be that the function "_digester" in reportlab.utils
seems not to return reliable hash values. That has lead to reuse of the
wrong images in my document. This happened randomly and was hard to find
the cause for it.

Here is the code:

-----------------8<---------------[cut here]
if sys.hexversion >= 0x02000000:
def _digester(s):
return md5(s).hexdigest()
else:
# hexdigest not available in 1.5
def _digester(s):
return join(map(lambda x : "%02x" % ord(x), md5(s).digest()), '')
-----------------8<---------------[cut here]

When working with StringIO in my image reader implementation the id() of
my object is passed to "_digester". But even if different id()s are
passed it seems that already used digest are returned. So please
consider to switch from "md5" to something else. I don't know if
"hash()" might return better results.

Cheers
Dirk


More information about the reportlab-users mailing list