libgdata/libgdata-crashes-on-zero-length-files.patch

114 lines
3.6 KiB
Diff

From 76e12748bd0e519caeeefd6e1ac7ce8086e63059 Mon Sep 17 00:00:00 2001
From: Ondrej Holy <oholy@redhat.com>
Date: Thu, 11 Aug 2016 08:58:00 +0200
Subject: [PATCH 1/2] core: Fix crashes on zero-length files
reached_eof is set too early and thus it may not be propagated properly
in some cases, which may cause abortion when reading zero-length files.
https://bugzilla.gnome.org/show_bug.cgi?id=769727
---
gdata/gdata-buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gdata/gdata-buffer.c b/gdata/gdata-buffer.c
index c8c1298f00f7..ce40f80f6249 100644
--- a/gdata/gdata-buffer.c
+++ b/gdata/gdata-buffer.c
@@ -231,10 +231,6 @@ gdata_buffer_pop_data (GDataBuffer *self, guint8 *data, gsize length_requested,
g_mutex_lock (&(self->mutex));
- /* Set reached_eof */
- if (reached_eof != NULL)
- *reached_eof = self->reached_eof && length_requested >= self->total_length;
-
if (self->reached_eof == TRUE && length_requested > self->total_length) {
/* Return data up to the EOF */
return_length = self->total_length;
@@ -259,6 +255,10 @@ gdata_buffer_pop_data (GDataBuffer *self, guint8 *data, gsize length_requested,
return_length = length_requested;
}
+ /* Set reached_eof */
+ if (reached_eof != NULL)
+ *reached_eof = self->reached_eof && length_requested >= self->total_length;
+
/* Return if we haven't got any data to pop (i.e. if we were cancelled before even one chunk arrived) */
if (return_length == 0)
goto done;
--
2.5.5
From 4b29a94a71317ffa9df282fef7f7be126687343a Mon Sep 17 00:00:00 2001
From: Ondrej Holy <oholy@redhat.com>
Date: Mon, 22 Aug 2016 12:02:44 +0200
Subject: [PATCH 2/2] tests: Add one more test for GDataBuffer
This test reproduces bug 769727.
https://bugzilla.gnome.org/show_bug.cgi?id=769727
---
gdata/tests/buffer.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/gdata/tests/buffer.c b/gdata/tests/buffer.c
index 02012d6cef75..c4e9d133bdc1 100644
--- a/gdata/tests/buffer.c
+++ b/gdata/tests/buffer.c
@@ -74,6 +74,41 @@ test_buffer_instant_eof (Fixture *f, gconstpointer user_data)
gdata_buffer_free (buffer);
}
+static gpointer
+test_buffer_thread_eof_func (gpointer user_data)
+{
+ GDataBuffer *buffer = user_data;
+
+ /* HACK: Wait for a while to be sure that gdata_buffer_pop_data() has
+ * been already called. */
+ g_usleep (G_USEC_PER_SEC / 2);
+
+ g_assert_false (gdata_buffer_push_data (buffer, NULL, 0));
+
+ return NULL;
+}
+
+/* The test needs to call gdata_buffer_push_data() from another thread only
+ * once gdata_buffer_pop_data() has reached its blocking loop. */
+static void
+test_buffer_thread_eof (Fixture *f, gconstpointer user_data)
+{
+ GDataBuffer *buffer = NULL; /* owned */
+ gboolean reached_eof = FALSE;
+ guint8 buf[1];
+
+ g_test_bug ("769727");
+
+ buffer = gdata_buffer_new ();
+
+ g_thread_new (NULL, test_buffer_thread_eof_func, buffer);
+ g_assert_cmpuint (gdata_buffer_pop_data (buffer, buf, sizeof (buf),
+ &reached_eof, NULL), ==, 0);
+ g_assert_true (reached_eof);
+
+ gdata_buffer_free (buffer);
+}
+
static void
test_buffer_basic (Fixture *f, gconstpointer user_data)
{
@@ -121,6 +156,8 @@ main (int argc, char *argv[])
set_up, test_buffer_construction, tear_down);
g_test_add ("/buffer/instant-eof", Fixture, NULL,
set_up, test_buffer_instant_eof, tear_down);
+ g_test_add ("/buffer/thread-eof", Fixture, NULL,
+ set_up, test_buffer_thread_eof, tear_down);
g_test_add ("/buffer/basic", Fixture, NULL,
set_up, test_buffer_basic, tear_down);
--
2.5.5