Blame SOURCES/0052-virtual-image-Fix-driver-reading-insufficient-data.patch

73b847
From 61851ea1f0a1e23c9f6f05245aa2d4d0303d1a88 Mon Sep 17 00:00:00 2001
73b847
From: Benjamin Berg <bberg@redhat.com>
73b847
Date: Mon, 2 Dec 2019 16:48:04 +0100
73b847
Subject: [PATCH 052/181] virtual-image: Fix driver reading insufficient data
73b847
73b847
In rare occasions it could happen that the driver was reading
73b847
insufficient data. Fix this by using g_input_stream_read_all_async
73b847
which will ensure that incomplete data will not be misinterpreted.
73b847
73b847
This fixes rare test failures seen in fprintd.
73b847
---
73b847
 libfprint/drivers/virtual-image.c | 46 ++++++++++++++++---------------
73b847
 1 file changed, 24 insertions(+), 22 deletions(-)
73b847
73b847
diff --git a/libfprint/drivers/virtual-image.c b/libfprint/drivers/virtual-image.c
73b847
index 612863d..c271c7a 100644
73b847
--- a/libfprint/drivers/virtual-image.c
73b847
+++ b/libfprint/drivers/virtual-image.c
73b847
@@ -66,13 +66,14 @@ recv_image_img_recv_cb (GObject      *source_object,
73b847
   g_autoptr(GError) error = NULL;
73b847
   FpDeviceVirtualImage *self;
73b847
   FpImageDevice *device;
73b847
-  gssize bytes;
73b847
+  gboolean success;
73b847
+  gsize bytes = 0;
73b847
 
73b847
-  bytes = g_input_stream_read_finish (G_INPUT_STREAM (source_object), res, &error);
73b847
+  success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
73b847
 
73b847
-  if (bytes <= 0)
73b847
+  if (!success || bytes == 0)
73b847
     {
73b847
-      if (bytes < 0)
73b847
+      if (!success)
73b847
         {
73b847
           g_warning ("Error receiving header for image data: %s", error->message);
73b847
           if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
73b847
@@ -103,13 +104,14 @@ recv_image_hdr_recv_cb (GObject      *source_object,
73b847
 {
73b847
   g_autoptr(GError) error = NULL;
73b847
   FpDeviceVirtualImage *self;
73b847
-  gssize bytes;
73b847
+  gboolean success;
73b847
+  gsize bytes;
73b847
 
73b847
-  bytes = g_input_stream_read_finish (G_INPUT_STREAM (source_object), res, &error);
73b847
+  success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
73b847
 
73b847
-  if (bytes <= 0)
73b847
+  if (!success || bytes == 0)
73b847
     {
73b847
-      if (bytes < 0)
73b847
+      if (!success)
73b847
         {
73b847
           g_warning ("Error receiving header for image data: %s", error->message);
73b847
           if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
73b847
@@ -158,25 +160,25 @@ recv_image_hdr_recv_cb (GObject      *source_object,
73b847
 
73b847
   self->recv_img = fp_image_new (self->recv_img_hdr[0], self->recv_img_hdr[1]);
73b847
   g_debug ("image data: %p", self->recv_img->data);
73b847
-  g_input_stream_read_async (G_INPUT_STREAM (source_object),
73b847
-                             (guint8 *) self->recv_img->data,
73b847
-                             self->recv_img->width * self->recv_img->height,
73b847
-                             G_PRIORITY_DEFAULT,
73b847
-                             self->cancellable,
73b847
-                             recv_image_img_recv_cb,
73b847
-                             self);
73b847
+  g_input_stream_read_all_async (G_INPUT_STREAM (source_object),
73b847
+                                 (guint8 *) self->recv_img->data,
73b847
+                                 self->recv_img->width * self->recv_img->height,
73b847
+                                 G_PRIORITY_DEFAULT,
73b847
+                                 self->cancellable,
73b847
+                                 recv_image_img_recv_cb,
73b847
+                                 self);
73b847
 }
73b847
 
73b847
 static void
73b847
 recv_image (FpDeviceVirtualImage *dev, GInputStream *stream)
73b847
 {
73b847
-  g_input_stream_read_async (stream,
73b847
-                             dev->recv_img_hdr,
73b847
-                             sizeof (dev->recv_img_hdr),
73b847
-                             G_PRIORITY_DEFAULT,
73b847
-                             dev->cancellable,
73b847
-                             recv_image_hdr_recv_cb,
73b847
-                             dev);
73b847
+  g_input_stream_read_all_async (stream,
73b847
+                                 dev->recv_img_hdr,
73b847
+                                 sizeof (dev->recv_img_hdr),
73b847
+                                 G_PRIORITY_DEFAULT,
73b847
+                                 dev->cancellable,
73b847
+                                 recv_image_hdr_recv_cb,
73b847
+                                 dev);
73b847
 }
73b847
 
73b847
 static void
73b847
-- 
73b847
2.24.1
73b847