[goffice] Don't crash when saving an invalid pixbuf. [#705005]



commit 60adace4c5025dc26c807e60589d8c6142e1923a
Author: Jean Brefort <jean brefort normalesup org>
Date:   Sun Jul 28 08:09:57 2013 +0200

    Don't crash when saving an invalid pixbuf. [#705005]

 ChangeLog                 |    6 ++++++
 NEWS                      |    2 +-
 goffice/utils/go-pixbuf.c |   19 ++++++++++++++-----
 3 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bf56b67..5656a6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-28  Jean Brefort  <jean brefort normalesup org>
+
+       * goffice/utils/go-pixbuf.c (go_pixbuf_save),
+       (go_pixbuf_load_data), (go_pixbuf_draw): fix more out of memory issues.
+       [#705005]
+
 2013-07-20  Jean Brefort  <jean brefort normalesup org>
 
        * goffice/utils/go-pixbuf.c (go_pixbuf_load_data): use g_try_malloc instead
diff --git a/NEWS b/NEWS
index fbacc55..28c2f6e 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,7 @@ goffice 0.10.5:
 Jean:
        * Don't crash when loading an EMF image without valid data. [#704311]
        * Fixed text and path items positions. [see #704391]
-       * Don't crash when loading a pixbuf with an invalid size. [#704560]
+       * Don't crash when a pixbuf has an invalid size. [#704560][#705005]
 
 Morten:
        * Add prescaling to go_linear_regression_leverage.  [#703381]
diff --git a/goffice/utils/go-pixbuf.c b/goffice/utils/go-pixbuf.c
index 9127be4..831ea0c 100644
--- a/goffice/utils/go-pixbuf.c
+++ b/goffice/utils/go-pixbuf.c
@@ -85,8 +85,11 @@ go_pixbuf_save (GOImage *image, GsfXMLOut *output)
        pixbuf = GO_PIXBUF (image);
        gsf_xml_out_add_int (output, "rowstride", pixbuf->rowstride);
        if (!image->data) {
-               image->data = g_new0 (guint8, image->height * pixbuf->rowstride);
-               g_return_if_fail (image->data !=NULL);
+               image->data = g_try_new0 (guint8, image->height * pixbuf->rowstride);
+               if (image->data == NULL) {
+                       g_critical ("go_pixbuf_save: assertion `image->data != NULL' failed");
+                       return;
+               }
                pixbuf_to_cairo (pixbuf);
        }
        gsf_xml_out_add_base64
@@ -117,7 +120,10 @@ go_pixbuf_load_data (GOImage *image, GsfXMLIn *xin)
        if (expected != length)
                g_critical ("Invalid image size, expected %lu bytes, got %lu", expected, length);
        image->data = g_try_malloc (expected);
-       g_return_if_fail (image->data != NULL);
+       if (image->data == NULL) {
+               g_critical ("go_pixbuf_load_data: assertion `image->data != NULL' failed");
+               return;
+       }
        memcpy (image->data, xin->content->str, MIN (length, expected));
        if (length < expected) /* fill with 0 */
                memset (image->data + length, 0, expected - length);
@@ -131,8 +137,11 @@ go_pixbuf_draw (GOImage *image, cairo_t *cr)
        if (pixbuf->surface == NULL) {
                if (image->data == NULL) {
                        /* image built from a pixbuf */
-                       image->data = g_new0 (guint8, image->height * pixbuf->rowstride);
-                       g_return_if_fail (image->data !=NULL);
+                       image->data = g_try_new0 (guint8, image->height * pixbuf->rowstride);
+                       if (image->data == NULL) {
+                               g_critical ("go_pixbuf_load_data: assertion `image->data != NULL' failed");
+                               return;
+                       }
                        pixbuf_to_cairo (pixbuf);
                }
                pixbuf->surface = cairo_image_surface_create_for_data (image->data,


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