[gtk/image-loading] !fixup tiff loader fixup fixup



commit 10eb152816214491b0ae7ec546977e9e3fa868ba
Author: Benjamin Otte <otte redhat com>
Date:   Tue Sep 14 03:44:14 2021 +0200

    !fixup tiff loader fixup fixup

 gdk/loaders/gdktiff.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/gdk/loaders/gdktiff.c b/gdk/loaders/gdktiff.c
index 3be4594acb..de5d0fcca3 100644
--- a/gdk/loaders/gdktiff.c
+++ b/gdk/loaders/gdktiff.c
@@ -68,6 +68,14 @@ tiff_io_error (const char *module,
   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, ap);
 }
 
+static tsize_t
+tiff_io_no_read (thandle_t handle,
+                 tdata_t   buffer,
+                 tsize_t   size)
+{
+  return (tsize_t) -1;
+}
+
 static tsize_t
 tiff_io_read (thandle_t handle,
               tdata_t   buffer,
@@ -76,6 +84,9 @@ tiff_io_read (thandle_t handle,
   TiffIO *io = (TiffIO *) handle;
   gsize read;
 
+  if (io->position >= io->size)
+    return 0;
+
   read = MIN (size, io->size - io->position);
 
   memcpy (buffer, io->data + io->position, read);
@@ -89,7 +100,6 @@ tiff_io_no_write (thandle_t handle,
                   tdata_t   buffer,
                   tsize_t   size)
 {
-  errno = EINVAL;
   return (tsize_t) -1;
 }
 
@@ -100,7 +110,8 @@ tiff_io_write (thandle_t handle,
 {
   TiffIO *io = (TiffIO *) handle;
 
-  if (io->size - io->position < size)
+  if (io->position > io->size ||
+      io->size - io->position < size)
     {
       io->size = io->position + size;
       io->data = g_realloc (io->data, io->size);
@@ -122,7 +133,6 @@ tiff_io_seek (thandle_t handle,
   switch (whence)
     {
     default:
-      errno = EINVAL;
       return -1;
     case SEEK_SET:
       break;
@@ -134,16 +144,7 @@ tiff_io_seek (thandle_t handle,
       break;
     }
   if (offset < 0)
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  if (offset > io->size)
-    {
-      /* Linux apparently can do that */
-      errno = EINVAL;
-      return -1;
-    }
+    return -1;
 
   io->position = offset;
 
@@ -207,7 +208,7 @@ tiff_open_write (GBytes **result)
 
   return TIFFClientOpen ("GTK-write", "w",
                          (thandle_t) io,
-                         tiff_io_read,
+                         tiff_io_no_read,
                          tiff_io_write,
                          tiff_io_seek,
                          tiff_io_close,


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