In case of an error (status != CAIRO_STATUS_SUCCESS) cairo_surface_write_to_png_stream seems to ignore what the write function actually returned. It always simply returns CAIRO_STATUS_NO_MEMORY (that's what that setjmp branch sets). A quick look at the source reveals that this probably isn't easy to change since png_rw_ptr doesn't have a return value, but I thought I file it anyway in case I missed something obvious. Feel free to dismiss this bug report if there is nothing that can be done about it.
I found a png_error_ptr through which we can propagate the error status. Pushed: commit 1469de5211e84e40490fa612538986768748bd55 Author: Chris Wilson <chris@chris-wilson.co.uk> Date: Tue Sep 25 23:35:25 2007 +0100 [cairo-png] Propagate error from read and write funcs. Use the png_struct->error_ptr to propagate the error status from the user/stdio read and write functions through the png_error() to the cairo_surface_write_to_png*() and cairo_surface_read_from_png*() functions. From there the error is returned back to the user either directly or as the most appropriate error surface. (Fixes https://bugs.freedesktop.org/show_bug.cgi?id=6909)
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.