[gtk/matthiasc/for-main] tiff loader: Catch more errors




commit 4d865cd7ba6124861e46dcfdf0fee4b6a7c903ad
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 13 17:51:24 2021 -0500

    tiff loader: Catch more errors
    
    tiff_open_read may fail, and we should not crash
    in that case but return an error.

 gdk/loaders/gdktiff.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gdk/loaders/gdktiff.c b/gdk/loaders/gdktiff.c
index 62e292a73d..724e4c3a81 100644
--- a/gdk/loaders/gdktiff.c
+++ b/gdk/loaders/gdktiff.c
@@ -240,7 +240,7 @@ static const FormatData format_data[] = {
   [GDK_MEMORY_A8R8G8B8]                         = { GDK_MEMORY_R8G8B8A8,                          8, 4, 
SAMPLEFORMAT_UINT,   EXTRASAMPLE_UNASSALPHA },
   [GDK_MEMORY_R8G8B8A8]                         = { GDK_MEMORY_R8G8B8A8,                          8, 4, 
SAMPLEFORMAT_UINT,   EXTRASAMPLE_UNASSALPHA },
   [GDK_MEMORY_A8B8G8R8]                         = { GDK_MEMORY_R8G8B8A8,                          8, 4, 
SAMPLEFORMAT_UINT,   EXTRASAMPLE_UNASSALPHA },
-  [GDK_MEMORY_R8G8B8]                           = { GDK_MEMORY_R8G8B8,                            8, 3, 
SAMPLEFORMAT_UINT,   0                      }, 
+  [GDK_MEMORY_R8G8B8]                           = { GDK_MEMORY_R8G8B8,                            8, 3, 
SAMPLEFORMAT_UINT,   0                      },
   [GDK_MEMORY_B8G8R8]                           = { GDK_MEMORY_R8G8B8,                            8, 3, 
SAMPLEFORMAT_UINT,   0                      },
   [GDK_MEMORY_R16G16B16]                        = { GDK_MEMORY_R16G16B16,                        16, 3, 
SAMPLEFORMAT_UINT,   0                      },
   [GDK_MEMORY_R16G16B16A16_PREMULTIPLIED]       = { GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,       16, 4, 
SAMPLEFORMAT_UINT,   EXTRASAMPLE_ASSOCALPHA },
@@ -376,6 +376,13 @@ gdk_load_tiff (GBytes  *input_bytes,
   G_GNUC_UNUSED gint64 before = GDK_PROFILER_CURRENT_TIME;
 
   tif = tiff_open_read (input_bytes);
+  if (!tif)
+    {
+      g_set_error_literal (error,
+                           GDK_TEXTURE_ERROR, GDK_TEXTURE_ERROR_CORRUPT_IMAGE,
+                           _("Could not load TIFF data"));
+      return NULL;
+    }
 
   TIFFSetDirectory (tif, 0);
 


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