[gthumb/gthumb-3-10] webp loader: fix g_input_stream_read return value check



commit 4e75172b4cdb10810be2460df13d0ab56fe6c878
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jun 22 07:10:33 2020 +0200

    webp loader: fix g_input_stream_read return value check
    
    `g_input_stream_read()` returns -1 on error. The return value check
    needs to be a signed integer comparison and thus, it has to happen
    before assigning the signed return value to the unsigned local variable
    `bytes_read`.
    
    This fixes an infinite loop when the operation is cancelled.
    
    Fixes: e99f14f9 ("make sure to read the requested amount of data...")

 extensions/cairo_io/cairo-image-surface-webp.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-image-surface-webp.c b/extensions/cairo_io/cairo-image-surface-webp.c
index e09766591..3bcfb8fe4 100644
--- a/extensions/cairo_io/cairo-image-surface-webp.c
+++ b/extensions/cairo_io/cairo-image-surface-webp.c
@@ -114,16 +114,20 @@ _cairo_image_surface_create_from_webp (GInputStream  *istream,
                return image;
        }
 
-       do {
+       while (TRUE) {
                VP8StatusCode status = WebPIAppend (idec, buffer, bytes_read);
                if ((status != VP8_STATUS_OK) && (status != VP8_STATUS_SUSPENDED))
                        break;
+
+               gssize signed_bytes_read = g_input_stream_read (istream,
+                                                              buffer,
+                                                              BUFFER_SIZE,
+                                                              cancellable,
+                                                              error);
+               if (signed_bytes_read <= 0)
+                       break;
+               bytes_read = signed_bytes_read;
        }
-       while ((bytes_read = g_input_stream_read (istream,
-                                                 buffer,
-                                                 BUFFER_SIZE,
-                                                 cancellable,
-                                                 error)) > 0);
 
        cairo_surface_mark_dirty (surface);
        if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]