From 911482e5ae88ba26a1b3290731968f8b8a80cd70 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 22 May 2009 23:44:27 +0100 Subject: [PATCH] [gl] Constrain image sources to max texture size --- src/cairo-gl-private.h | 2 ++ src/cairo-gl-surface.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h index 47ebd01d9..3d37fe091 100644 --- a/src/cairo-gl-private.h +++ b/src/cairo-gl-private.h @@ -65,6 +65,8 @@ struct _cairo_gl_context { cairo_mutex_t mutex; /* needed? */ GLuint dummy_tex; + GLint max_framebuffer_size; + GLint max_texture_size; cairo_gl_surface_t *current_target; diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index d54c0a206..df130f84e 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -130,6 +130,11 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx) glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + ctx->max_framebuffer_size = 0; + glGetIntegerv (GL_MAX_RENDERBUFFER_SIZE, &ctx->max_framebuffer_size); + ctx->max_texture_size = 0; + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &ctx->max_texture_size); + return CAIRO_STATUS_SUCCESS; } @@ -459,6 +464,9 @@ cairo_gl_surface_create (cairo_gl_context_t *ctx, if (ctx->status) return _cairo_surface_create_in_error (ctx->status); + if (width > ctx->max_framebuffer_size || height > ctx->max_framebuffer_size) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); + surface = calloc (1, sizeof (cairo_gl_surface_t)); if (unlikely (surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); @@ -584,6 +592,12 @@ _cairo_gl_surface_create_similar (void *abstract_surface, assert (CAIRO_CONTENT_VALID (content)); + if (width > surface->ctx->max_framebuffer_size || + height > surface->ctx->max_framebuffer_size) + { + return NULL; + } + if (width < 1) width = 1; if (height < 1) @@ -946,6 +960,11 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, return CAIRO_INT_STATUS_UNSUPPORTED; image_surface = (cairo_image_surface_t *)surface_pattern->surface; + if (image_surface->width > dst->ctx->max_texture_size || + image_surface->height > dst->ctx->max_texture_size) + { + return CAIRO_INT_STATUS_UNSUPPORTED; + } /* The textures we create almost always has appropriate alpha channel * contents. But sometimes GL sucks at image specification and we end up