From 26ee41435b864b266f6c2c06544d95f7cd125733 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 1 Jul 2011 18:53:18 +0200 Subject: [PATCH] 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 --- src/cairo-xlib-xcb-surface.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/cairo-xlib-xcb-surface.c b/src/cairo-xlib-xcb-surface.c index 16fabd876..b48cb9293 100644 --- a/src/cairo-xlib-xcb-surface.c +++ b/src/cairo-xlib-xcb-surface.c @@ -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; }