Blame SOURCES/evince-3.28.2-TIFFReadRGBAImageOriented.patch

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