[gtk/image-loading: 24/36] png: loader set error
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/image-loading: 24/36] png: loader set error
- Date: Tue, 14 Sep 2021 05:40:47 +0000 (UTC)
commit b67e879499197bc367ee6e621ee0e556992d4b30
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 13 20:52:08 2021 -0400
png: loader set error
gdk/loaders/gdkpng.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/gdk/loaders/gdkpng.c b/gdk/loaders/gdkpng.c
index 8992fb0faa..9aca6fe682 100644
--- a/gdk/loaders/gdkpng.c
+++ b/gdk/loaders/gdkpng.c
@@ -95,14 +95,40 @@ gdk_load_png (GBytes *bytes,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes));
+ if (PNG_IMAGE_FAILED (image))
+ {
+ g_set_error (error,
+ GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED,
+ "Failed to parse png image (%s)", image.message);
+ png_image_free (&image);
+ return NULL;
+ }
+
image.format = PNG_FORMAT_RGBA;
stride = PNG_IMAGE_ROW_STRIDE (image);
size = PNG_IMAGE_BUFFER_SIZE (image, stride);
- buffer = g_malloc (size);
+ buffer = g_try_malloc (size);
+ if (!buffer)
+ {
+ g_set_error_literal (error,
+ GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
+ "Not enough memory to load png");
+ png_image_free (&image);
+ return NULL;
+ }
png_image_finish_read (&image, NULL, buffer, stride, NULL);
+ if (PNG_IMAGE_FAILED (image))
+ {
+ g_set_error (error,
+ GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_UNSUPPORTED,
+ "Failed to parse png image (%s)", image.message);
+ png_image_free (&image);
+ return NULL;
+ }
+
if (image.format & PNG_FORMAT_FLAG_LINEAR)
stride *= 2;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]