From f93a84c015a53f6fa89f2af04ad004631d8b7442 Mon Sep 17 00:00:00 2001
From: Marek Kasik <mkasik@redhat.com>
Date: Wed, 11 Feb 2015 12:13:40 +0100
Subject: Check for failed rendering jobs
Check whether creating of thumbnails for sidebar, thumbnails for recent view
or rendering of document itself failed to avoid crashes.
https://bugzilla.gnome.org/show_bug.cgi?id=744049
https://bugzilla.gnome.org/show_bug.cgi?id=744586
---
libdocument/ev-document.c | 8 +++++---
libview/ev-jobs.c | 26 +++++++++++++++++++++++++-
libview/ev-pixbuf-cache.c | 6 ++++++
shell/ev-recent-view.c | 3 ++-
shell/ev-sidebar-thumbnails.c | 5 +++++
5 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index 6c2f1b9..6af0ad7 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -724,11 +724,13 @@ _ev_document_get_thumbnail (EvDocument *document,
EvRenderContext *rc)
{
cairo_surface_t *surface;
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf = NULL;
surface = ev_document_render (document, rc);
- pixbuf = ev_document_misc_pixbuf_from_surface (surface);
- cairo_surface_destroy (surface);
+ if (surface != NULL) {
+ pixbuf = ev_document_misc_pixbuf_from_surface (surface);
+ cairo_surface_destroy (surface);
+ }
return pixbuf;
}
diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c
index 3337276..d338666 100644
--- a/libview/ev-jobs.c
+++ b/libview/ev-jobs.c
@@ -637,6 +637,21 @@ ev_job_render_run (EvJob *job)
g_object_unref (ev_page);
job_render->surface = ev_document_render (job->document, rc);
+
+ if (job_render->surface == NULL) {
+ ev_document_fc_mutex_unlock ();
+ ev_document_doc_mutex_unlock ();
+ g_object_unref (rc);
+
+ ev_job_failed (job,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Failed to render page %d"),
+ job_render->page);
+
+ return FALSE;
+ }
+
/* If job was cancelled during the page rendering,
* we return now, so that the thread is finished ASAP
*/
@@ -873,7 +888,16 @@ ev_job_thumbnail_run (EvJob *job)
g_object_unref (pixbuf);
}
- ev_job_succeeded (job);
+ if ((job_thumb->format == EV_JOB_THUMBNAIL_PIXBUF && pixbuf == NULL) ||
+ job_thumb->thumbnail_surface == NULL) {
+ ev_job_failed (job,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("Failed to create thumbnail for page %d"),
+ job_thumb->page);
+ } else {
+ ev_job_succeeded (job);
+ }
return FALSE;
}
diff --git a/libview/ev-pixbuf-cache.c b/libview/ev-pixbuf-cache.c
index f308c9c..c7ae47a 100644
--- a/libview/ev-pixbuf-cache.c
+++ b/libview/ev-pixbuf-cache.c
@@ -337,6 +337,12 @@ job_finished_cb (EvJob *job,
job_info = find_job_cache (pixbuf_cache, job_render->page);
+ if (ev_job_is_failed (job)) {
+ job_info->job = NULL;
+ g_object_unref (job);
+ return;
+ }
+
copy_job_to_job_info (job_render, job_info, pixbuf_cache);
g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
}
diff --git a/shell/ev-recent-view.c b/shell/ev-recent-view.c
index facea47..2dabf86 100644
--- a/shell/ev-recent-view.c
+++ b/shell/ev-recent-view.c
@@ -350,7 +350,8 @@ static void
thumbnail_job_completed_callback (EvJobThumbnail *job,
GetDocumentInfoAsyncData *data)
{
- if (g_cancellable_is_cancelled (data->cancellable)) {
+ if (g_cancellable_is_cancelled (data->cancellable) ||
+ ev_job_is_failed (EV_JOB (job))) {
get_document_info_async_data_free (data);
return;
}
diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c
index 78b4b31..9374034 100644
--- a/shell/ev-sidebar-thumbnails.c
+++ b/shell/ev-sidebar-thumbnails.c
@@ -934,7 +934,12 @@ thumbnail_job_completed_callback (EvJobThumbnail *job,
cairo_surface_t *surface;
#ifdef HAVE_HIDPI_SUPPORT
gint device_scale;
+#endif
+
+ if (ev_job_is_failed (EV_JOB (job)))
+ return;
+#ifdef HAVE_HIDPI_SUPPORT
device_scale = gtk_widget_get_scale_factor (widget);
cairo_surface_set_device_scale (job->thumbnail_surface, device_scale, device_scale);
#endif
--
cgit v0.12