xlib-xcb: Verify we really have an xcb surface

If the X11 server doesn't have the RENDER extension, the xcb backend falls back
to the image backend in some cases (e.g. create_similar). xlib-xcb didn't handle
this properly which means it used the result like a xcb surface.

Found while debugging https://bugs.freedesktop.org/show_bug.cgi?id=31931,
firefox died from a BadDrawable error when it tried to use the (bogous) result
from cairo_xlib_surface_get_drawable().

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2011-07-01 18:53:18 +02:00
parent 59fadcf7d9
commit 26ee41435b

View file

@ -485,6 +485,12 @@ cairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface)
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
/* This can happen when e.g. create_similar falls back to an image surface
* because we don't have the RENDER extension. */
if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) {
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
return surface->xcb->drawable;
}
@ -524,6 +530,12 @@ cairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface)
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
/* This can happen when e.g. create_similar falls back to an image surface
* because we don't have the RENDER extension. */
if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) {
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
return surface->xcb->depth;
}
@ -537,6 +549,12 @@ cairo_xlib_surface_get_width (cairo_surface_t *abstract_surface)
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
/* This can happen when e.g. create_similar falls back to an image surface
* because we don't have the RENDER extension. */
if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) {
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
return surface->xcb->width;
}
@ -550,6 +568,12 @@ cairo_xlib_surface_get_height (cairo_surface_t *abstract_surface)
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
/* This can happen when e.g. create_similar falls back to an image surface
* because we don't have the RENDER extension. */
if (surface->xcb->base.type != CAIRO_SURFACE_TYPE_XCB) {
_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return 0;
}
return surface->xcb->height;
}