[gthumb: 129/129] don't try to create cairo surfaces bigger then 32767



commit c4baadb8b85ee27094400b2a475a98f3439f4e77
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Apr 27 21:29:02 2011 +0200

    don't try to create cairo surfaces bigger then 32767

 extensions/cairo_io/cairo-io-jpeg.c |   13 +++++++++++--
 gthumb/cairo-utils.h                |    2 ++
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-io-jpeg.c b/extensions/cairo_io/cairo-io-jpeg.c
index f020a99..7987a4f 100644
--- a/extensions/cairo_io/cairo-io-jpeg.c
+++ b/extensions/cairo_io/cairo-io-jpeg.c
@@ -216,8 +216,8 @@ _cairo_image_surface_create_from_jpeg (GthFileData   *file_data,
 
 	orientation = _jpeg_exif_orientation (in_buffer, in_buffer_size);
 	_cairo_image_surface_transform_get_steps (CAIRO_FORMAT_ARGB32,
-						  srcinfo.output_width,
-						  srcinfo.output_height,
+						  MIN (srcinfo.output_width, CAIRO_MAX_IMAGE_SIZE),
+						  MIN (srcinfo.output_height, CAIRO_MAX_IMAGE_SIZE),
 						  orientation,
 						  &destination_width,
 						  &destination_height,
@@ -235,6 +235,15 @@ _cairo_image_surface_create_from_jpeg (GthFileData   *file_data,
 #endif
 
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, destination_width, destination_height);
+	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
+		/* g_warning ("%s", cairo_status_to_string (cairo_surface_status (surface))); */
+
+		jpeg_destroy ((j_common_ptr) &srcinfo);
+		cairo_surface_destroy (surface);
+		g_free (in_buffer);
+
+		return image;
+	}
 	cairo_surface_flush (surface);
 	surface_row = cairo_image_surface_get_data (surface) + line_start;
 
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index 21d6f03..bd18cfc 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -29,6 +29,8 @@
 #include "typedefs.h"
 
 
+#define CAIRO_MAX_IMAGE_SIZE 32767
+
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN /* BGRA */
 
 #define CAIRO_RED   2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]