gdk_cairo_surface_create_from_pixbuf() fails to check if creating the surface succeeded
Submitted by Phillip Berndt
Link to original bug (#736624)
Description
Created attachment 286134 pixbuf-fix.patch
In my image viewer, I use gdk_cairo_surface_create_from_pixbuf() to transfer an image I loaded using gdk-pixbuf to a cairo surface. The function calls gdk_window_create_similar_image_surface() to create a surface and then renders to it using gdk_cairo_surface_paint_pixbuf(), without checking if the returned surface is valid. This causes a segfault if the surface is invalid. (Cairo returns a reference on an invalid surface instead of returning NULL if something failed. [1])
A way to trigger this bug is to use a large image which is larger than 32767px in one dimension. My example is a stitched panorama of 326815x1330 pixels. gdk-pixbuf can handle this, but cairo cannot. [2]
The function should check if the surface is valid before trying to paint to it. If it is invalid, I find it reasonable to return the reference to the invalid surface instead of NULL, because cairo users will expect that. I'll attach a patch makes it do just that.
[1] http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-create [2] http://comments.gmane.org/gmane.comp.lib.cairo/21068
Patch 286134, "pixbuf-fix.patch":
0001-gdk-cairo-In-gdk_cairo_surface_create_from_pixbuf-ch.patch
Version: 3.13.x