Blame SOURCES/evince-3.28.2-TIFFReadRGBAImageOriented.patch

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