[cairo] [PATCH] Generate better error message when loading invalid PNGs

Adrian Johnson ajohnson at redneon.com
Fri Mar 25 21:11:15 UTC 2016

On 26/03/16 03:53, Uli Schlachter wrote:
> Based on an idea from Cyril Roelandt, this patch makes cairo generate better
> error messages when cairo_image_surface_create_from_png{,_stream} is called on
> e.g. JPEG files. To do so, we don't let libpng check if the file starts with a
> PNG signature, but do so by hand. On mismatch, a surface with status
> CAIRO_STATUS_READ_ERROR is returned where previously the status was
> CAIRO_STATUS_NO_MEMORY (the status used for all errors in libpng).

What about if it is a PNG file but libpng is unable to decode it? It is
still going to return the unhelpful CAIRO_STATUS_NO_MEMORY. It is also
useful restrict CAIRO_STATUS_READ_ERROR to errors reading the from the

I think we need an error status for backends that can fail. The attached
patch adds CAIRO_STATUS_PNG_ERROR. I can also write a patch for win32 as
it is returning CAIRO_STATUS_NO_MEMORY for GDI errors.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-CAIRO_STATUS_PNG_ERROR-for-errors-returned-by-li.patch
Type: text/x-patch
Size: 7044 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160326/dbc52780/attachment-0001.bin>

More information about the cairo mailing list