Backport fix for crashes with zero-length files (GNOME #769727)

This commit is contained in:
Debarshi Ray 2016-09-12 17:19:55 +02:00
parent bc05e70efe
commit 8bde6720a8
2 changed files with 121 additions and 1 deletions

View File

@ -0,0 +1,113 @@
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

View File

@ -1,6 +1,6 @@
Name: libgdata
Version: 0.17.5
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Library for the GData protocol
Group: System Environment/Libraries
@ -8,6 +8,9 @@ License: LGPLv2+
URL: http://live.gnome.org/libgdata
Source0: http://download.gnome.org/sources/%{name}/0.17/%{name}-%{version}.tar.xz
# https://bugzilla.gnome.org/show_bug.cgi?id=769727
Patch0: libgdata-crashes-on-zero-length-files.patch
BuildRequires: gcr-devel
BuildRequires: glib2-devel
BuildRequires: gnome-online-accounts-devel
@ -44,6 +47,7 @@ developing applications that use %{name}.
%prep
%setup -q
%patch0 -p1
%build
%configure \
@ -86,6 +90,9 @@ find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
%{_datadir}/vala/
%changelog
* Mon Sep 12 2016 Debarshi Ray <rishi@fedoraproject.org> - 0.17.5-2
- Backport fix for crashes with zero-length files (GNOME #769727)
* Thu Jun 30 2016 Kalev Lember <klember@redhat.com> - 0.17.5-1
- Update to 0.17.5