Blame SOURCES/evince-3.28.2-TIFFReadRGBAImageOriented.patch

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