changeset 97012:c5f36ea75cba

(svg_load_image): Use rsvg_handle_get_dimensions to check that image size is valid. Use g_object_unref instead of deprecated rsvg_handle_free to free rsvg handle.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 25 Jul 2008 17:06:23 +0000
parents 54da3cfc73f9
children 193725c098b7
files src/image.c
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/image.c	Fri Jul 25 17:06:06 2008 +0000
+++ b/src/image.c	Fri Jul 25 17:06:23 2008 +0000
@@ -8841,7 +8841,7 @@
 
 /* SVG library functions.  */
 DEF_IMGLIB_FN (rsvg_handle_new);
-DEF_IMGLIB_FN (rsvg_handle_set_size_callback);
+DEF_IMGLIB_FN (rsvg_handle_get_dimensions);
 DEF_IMGLIB_FN (rsvg_handle_write);
 DEF_IMGLIB_FN (rsvg_handle_close);
 DEF_IMGLIB_FN (rsvg_handle_get_pixbuf);
@@ -8873,7 +8873,7 @@
     return 0;
 
   LOAD_IMGLIB_FN (library, rsvg_handle_new);
-  LOAD_IMGLIB_FN (library, rsvg_handle_set_size_callback);
+  LOAD_IMGLIB_FN (library, rsvg_handle_get_dimensions);
   LOAD_IMGLIB_FN (library, rsvg_handle_write);
   LOAD_IMGLIB_FN (library, rsvg_handle_close);
   LOAD_IMGLIB_FN (library, rsvg_handle_get_pixbuf);
@@ -8898,7 +8898,7 @@
 /* The following aliases for library functions allow dynamic loading
    to be used on some platforms.  */
 #define fn_rsvg_handle_new		rsvg_handle_new
-#define fn_rsvg_handle_set_size_callback rsvg_handle_set_size_callback
+#define fn_rsvg_handle_get_dimensions   rsvg_handle_get_dimensions
 #define fn_rsvg_handle_write		rsvg_handle_write
 #define fn_rsvg_handle_close		rsvg_handle_close
 #define fn_rsvg_handle_get_pixbuf	rsvg_handle_get_pixbuf
@@ -8993,6 +8993,7 @@
      unsigned int size;
 {
   RsvgHandle *rsvg_handle;
+  RsvgDimensionData dimension_data;
   GError *error = NULL;
   GdkPixbuf *pixbuf;
   int width;
@@ -9013,21 +9014,22 @@
 
   /* Parse the contents argument and fill in the rsvg_handle.  */
   fn_rsvg_handle_write (rsvg_handle, contents, size, &error);
-  if (error)
-    goto rsvg_error;
+  if (error) goto rsvg_error;
 
   /* The parsing is complete, rsvg_handle is ready to used, close it
      for further writes.  */
   fn_rsvg_handle_close (rsvg_handle, &error);
-  if (error)
+  if (error) goto rsvg_error;
+
+  fn_rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
+  if (! check_image_size (f, dimension_data.width, dimension_data.height))
     goto rsvg_error;
 
   /* We can now get a valid pixel buffer from the svg file, if all
      went ok.  */
   pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle);
-  fn_rsvg_handle_free (rsvg_handle);
-  if (!pixbuf)
-    goto rsvg_error;
+  if (!pixbuf) goto rsvg_error;
+  fn_g_object_unref (rsvg_handle);
 
   /* Extract some meta data from the svg handle.  */
   width     = fn_gdk_pixbuf_get_width (pixbuf);
@@ -9148,6 +9150,7 @@
   return 1;
 
  rsvg_error:
+  fn_g_object_unref (rsvg_handle);
   /* FIXME: Use error->message so the user knows what is the actual
      problem with the image.  */
   image_error ("Error parsing SVG image `%s'", img->spec, Qnil);