[goffice] pixbuf: a bit more checks.



commit 9151f135a3d52039b06380c9551a144ecb5fae9c
Author: Morten Welinder <terra gnome org>
Date:   Sat Jul 20 19:46:54 2013 -0400

    pixbuf: a bit more checks.

 goffice/utils/go-pixbuf.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/goffice/utils/go-pixbuf.c b/goffice/utils/go-pixbuf.c
index 781a5d8..9127be4 100644
--- a/goffice/utils/go-pixbuf.c
+++ b/goffice/utils/go-pixbuf.c
@@ -107,13 +107,18 @@ static void
 go_pixbuf_load_data (GOImage *image, GsfXMLIn *xin)
 {
        size_t length, expected;
+       int stride;
+
+       stride = go_pixbuf_get_rowstride (GO_PIXBUF (image));
+       g_return_if_fail (stride > 0);
+
        length = gsf_base64_decode_simple (xin->content->str, strlen(xin->content->str));
-       expected = image->height * go_pixbuf_get_rowstride (GO_PIXBUF (image));
+       expected = image->height * stride;
        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);
-       memcpy (image->data, xin->content->str, (length < expected)? length: expected);
+       memcpy (image->data, xin->content->str, MIN (length, expected));
        if (length < expected) /* fill with 0 */
                memset (image->data + length, 0, expected - length);
 }


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