libfprint/SOURCES/0052-virtual-image-Fix-driv...

100 lines
3.9 KiB
Diff

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