[gtk/image-loading: 25/36] jpeg: Set errors
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/image-loading: 25/36] jpeg: Set errors
- Date: Tue, 14 Sep 2021 05:40:47 +0000 (UTC)
commit 6fa2e195f3ac21f05fa81ecfa99fb4067a96e743
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 13 20:55:53 2021 -0400
jpeg: Set errors
gdk/loaders/gdkjpeg.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/gdk/loaders/gdkjpeg.c b/gdk/loaders/gdkjpeg.c
index dc17c7f26e..74a1c9623a 100644
--- a/gdk/loaders/gdkjpeg.c
+++ b/gdk/loaders/gdkjpeg.c
@@ -44,9 +44,20 @@ static void
fatal_error_handler (j_common_ptr cinfo)
{
struct error_handler_data *errmgr;
+ char buffer[JMSG_LENGTH_MAX];
errmgr = (struct error_handler_data *) cinfo->err;
+ cinfo->err->format_message (cinfo, buffer);
+
+ if (errmgr->error && *errmgr->error == NULL)
+ g_set_error (errmgr->error,
+ GDK_TEXTURE_ERROR,
+ cinfo->err->msg_code == JERR_OUT_OF_MEMORY
+ ? GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY
+ : GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
+ "Error interpreting JPEG image file (%s)", buffer);
+
siglongjmp (errmgr->setjmp_buffer, 1);
g_assert_not_reached ();
@@ -100,7 +111,15 @@ gdk_load_jpeg (GBytes *input_bytes,
height = info.output_height;
size = width * height * 3;
- data = g_malloc (size);
+ data = g_try_malloc_n (width * 3, height);
+ if (!data)
+ {
+ g_set_error_literal (error,
+ GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_INSUFFICIENT_MEMORY,
+ "Not enough memory to load jpeg");
+ jpeg_destroy_decompress (&info);
+ return NULL;
+ }
while (info.output_scanline < info.output_height)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]