[cairo] PyCairo - Crash on Windows build, in either zlib or PyCairo

CJ Kucera pez at apocalyptech.com
Thu Mar 19 21:57:42 PDT 2009

Hello list!

I've been developing an app in Python which uses PyCairo, which is meant
to be cross-platform.  I've been developing on Linux, and when testing
on Windows, I started having really bizarre problems with crashing, with
a generic "python.exe has generated errors and will be closed by Windows" 
message.  I'll spare you the details of tracking it down, but in the end
it can boil down to a very short script which I've put up here:


I'm not yet sure if the problem is in Python's builtin zlib functions,
or in PyCairo's ImageSurface.create_from_png().  When I'm decompressing
zlib-based data and I *don't* specify bufsize, the cairo call in there
will end up generating a crash.  If I *do* specify an appropriate
bufsize, then the call to Cairo ends up working just fine. [1]

Since it's in the Cairo call that the program actually crashes, Cairo is
certainly a suspect there, but I can't help but think that perhaps zlib
is at fault...  Python's documentation mentions malloc() behavior in the
zlib.decompress() reference, which makes me think that perhaps it's
clobbering memory where it shouldn't, and the Cairo call just happens to
run up against the area of memory that's been clobbered.

That having been said, though, I haven't yet been able to reproduce the
problem with anything other than that create_from_png() call.

So anyway, I'm hoping more eyes will help get this figured out.  I've
got a list of software versions that I've been able to reproduce this
with at the above URL, but here it is for completeness' sake:

Windows versions: XP and win2k
Python versions:
  Python 2.5.4 with:
    PyGTK 2.12.1-2-win32-py2.5
    PyGObject 2.14.1-1.win32-py2.5
    PyCairo 1.4.12-1.win32-py2.5
  Python 2.6.1 with:
    PyGTK 2.12.1-3-win32-py2.6
    PyGObject 2.14.2-2.win32-py2.6
    PyCairo 1.4.12-2.win32-py2.6
GTK versions used:
  gtk+ 2.12.9-win32-2 from the gladewin32 project
  gtk+-bundle 2.16.0-20090317_win32, from the other link on pygtk's
  download page

Somewhat notably, PyCairo is one of the few components that I've not
had the opportunity to try multiple versions on, really.  The Python 2.5
and Python 2.6 versions are, I'm sure, almost identical.

I mention it on the page, but I'll mention it here once more: in Linux,
this problem simply doesn't happen.  It's just a problem with the
Windows builds.

Thanks, and apologies for the long-winded post!


[1] At least it does for this test app.  When I plugged in that fix to
my larger app, I found that I did eventually experience the same
crashing problem, though far less often (enough so that the app is at
least usable on Windows).  So specifying a bufsize doesn't completely
alleviate the problem.

More information about the cairo mailing list