Blame SOURCES/evince-3.28.2-TIFFReadRGBAImageOriented.patch

8f7609
From 3e38d5ad724a042eebadcba8c2d57b0f48b7a8c7 Mon Sep 17 00:00:00 2001
8f7609
From: Jason Crain <jcrain@src.gnome.org>
8f7609
Date: Mon, 15 Apr 2019 23:06:36 -0600
8f7609
Subject: [PATCH] tiff: Handle failure from TIFFReadRGBAImageOriented
8f7609
8f7609
The TIFFReadRGBAImageOriented function returns zero if it was unable to
8f7609
read the image. Return NULL in this case instead of displaying
8f7609
uninitialized memory.
8f7609
8f7609
Fixes #1129
8f7609
---
8f7609
 backend/tiff/tiff-document.c | 28 ++++++++++++++++++----------
8f7609
 1 file changed, 18 insertions(+), 10 deletions(-)
8f7609
8f7609
diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c
8f7609
index 7715031b..38bb3bd8 100644
8f7609
--- a/backend/tiff/tiff-document.c
8f7609
+++ b/backend/tiff/tiff-document.c
8f7609
@@ -292,18 +292,22 @@ tiff_document_render (EvDocument      *document,
8f7609
 		g_warning("Failed to allocate memory for rendering.");
8f7609
 		return NULL;
8f7609
 	}
8f7609
-	
8f7609
+
8f7609
+	if (!TIFFReadRGBAImageOriented (tiff_document->tiff,
8f7609
+					width, height,
8f7609
+					(uint32 *)pixels,
8f7609
+					orientation, 0)) {
8f7609
+		g_warning ("Failed to read TIFF image.");
8f7609
+		g_free (pixels);
8f7609
+		return NULL;
8f7609
+	}
8f7609
+
8f7609
 	surface = cairo_image_surface_create_for_data (pixels,
8f7609
 						       CAIRO_FORMAT_RGB24,
8f7609
 						       width, height,
8f7609
 						       rowstride);
8f7609
 	cairo_surface_set_user_data (surface, &key,
8f7609
 				     pixels, (cairo_destroy_func_t)g_free);
8f7609
-
8f7609
-	TIFFReadRGBAImageOriented (tiff_document->tiff,
8f7609
-				   width, height,
8f7609
-				   (uint32 *)pixels,
8f7609
-				   orientation, 0);
8f7609
 	pop_handlers ();
8f7609
 
8f7609
 	/* Convert the format returned by libtiff to
8f7609
@@ -384,13 +388,17 @@ tiff_document_get_thumbnail (EvDocument      *document,
8f7609
 	if (!pixels)
8f7609
 		return NULL;
8f7609
 	
8f7609
+	if (!TIFFReadRGBAImageOriented (tiff_document->tiff,
8f7609
+					width, height,
8f7609
+					(uint32 *)pixels,
8f7609
+					ORIENTATION_TOPLEFT, 0)) {
8f7609
+		g_free (pixels);
8f7609
+		return NULL;
8f7609
+	}
8f7609
+
8f7609
 	pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, 
8f7609
 					   width, height, rowstride,
8f7609
 					   (GdkPixbufDestroyNotify) g_free, NULL);
8f7609
-	TIFFReadRGBAImageOriented (tiff_document->tiff,
8f7609
-				   width, height,
8f7609
-				   (uint32 *)pixels,
8f7609
-				   ORIENTATION_TOPLEFT, 0);
8f7609
 	pop_handlers ();
8f7609
 
8f7609
 	ev_render_context_compute_scaled_size (rc, width, height * (x_res / y_res),
8f7609
-- 
8f7609
2.21.0
8f7609