summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-png.c
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-01-18 11:15:33 +0000
committerPhilip Withnall <withnall@endlessm.com>2017-02-07 11:08:42 +0000
commit71e3b4a413a03627475944781f376da909de8dd5 (patch)
tree6a239e837df4ae213fa2fb2c070aeab5f40ad8cf /gdk-pixbuf/io-png.c
parent3dacbb48f0ca67d1b7124f6de58796a517dbed53 (diff)
downloadgdk-pixbuf-71e3b4a413a03627475944781f376da909de8dd5.tar.gz
gdk-pixbuf-io: Add precondition checks for image dimensions
Refuse to save an invalid GdkPixbuf: one which has negative width, height or number of channels. This allows us to put assertions for all those properties in the I/O code, which helps static analysis not go off on one because it thinks the image width could be negative. Coverity ID: 1388534 https://bugzilla.gnome.org/show_bug.cgi?id=777374
Diffstat (limited to 'gdk-pixbuf/io-png.c')
-rw-r--r--gdk-pixbuf/io-png.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c
index 364d5859b..a9fc1f6bf 100644
--- a/gdk-pixbuf/io-png.c
+++ b/gdk-pixbuf/io-png.c
@@ -1061,6 +1061,11 @@ static gboolean real_save_png (GdkPixbuf *pixbuf,
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
pixels = gdk_pixbuf_get_pixels (pixbuf);
+ /* Guaranteed by the caller. */
+ g_assert (w >= 0);
+ g_assert (h >= 0);
+ g_assert (rowstride >= 0);
+
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING,
error,
png_simple_error_callback,