[gimp] Bug 731390 - XCF files have a max size of 4G



commit 0c58dcd5cd9928db03e780cad3709a3a962c611d
Author: Michael Natterer <mitch gimp org>
Date:   Thu Mar 23 12:42:38 2017 +0100

    Bug 731390 - XCF files have a max size of 4G
    
    Change the xcf_write_foo() functions to take the XcfInfo* instead of
    a GOutputStream*, and make them advance the info->cp offset by
    themselves.

 app/xcf/xcf-save.c  |   74 +++++++++++++++++++++++++-------------------------
 app/xcf/xcf-write.c |   65 ++++++++++++++++++++++++--------------------
 app/xcf/xcf-write.h |   12 ++++----
 3 files changed, 78 insertions(+), 73 deletions(-)
---
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index a89c349..4579d4a 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -130,8 +130,17 @@ static gboolean xcf_save_vectors       (XcfInfo           *info,
 
 
 /* private convenience macros */
-#define xcf_write_int32_check_error(info, data, count) G_STMT_START {  \
-  info->cp += xcf_write_int32 (info->output, data, count, &tmp_error); \
+#define xcf_write_int32_check_error(info, data, count) G_STMT_START { \
+  xcf_write_int32 (info, data, count, &tmp_error);                    \
+  if (tmp_error)                                                      \
+    {                                                                 \
+      g_propagate_error (error, tmp_error);                           \
+      return FALSE;                                                   \
+    }                                                                 \
+  } G_STMT_END
+
+#define xcf_write_offset_check_error(info, data, count) G_STMT_START { \
+  xcf_write_offset (info, data, count, &tmp_error);                    \
   if (tmp_error)                                                       \
     {                                                                  \
       g_propagate_error (error, tmp_error);                            \
@@ -139,26 +148,26 @@ static gboolean xcf_save_vectors       (XcfInfo           *info,
     }                                                                  \
   } G_STMT_END
 
-#define xcf_write_offset_check_error(info, data, count) G_STMT_START {  \
-  info->cp += xcf_write_offset (info->output, data, count, &tmp_error); \
-  if (tmp_error)                                                        \
-    {                                                                   \
-      g_propagate_error (error, tmp_error);                             \
-      return FALSE;                                                     \
-    }                                                                   \
+#define xcf_write_zero_offset_check_error(info, count) G_STMT_START { \
+  xcf_write_zero_offset (info, count, &tmp_error);                    \
+  if (tmp_error)                                                      \
+    {                                                                 \
+      g_propagate_error (error, tmp_error);                           \
+      return FALSE;                                                   \
+    }                                                                 \
   } G_STMT_END
 
-#define xcf_write_zero_offset_check_error(info, count) G_STMT_START {  \
-  info->cp += xcf_write_zero_offset (info->output, count, &tmp_error); \
-  if (tmp_error)                                                       \
-    {                                                                  \
-      g_propagate_error (error, tmp_error);                            \
-      return FALSE;                                                    \
-    }                                                                  \
+#define xcf_write_int8_check_error(info, data, count) G_STMT_START { \
+  xcf_write_int8 (info, data, count, &tmp_error);                    \
+  if (tmp_error)                                                     \
+    {                                                                \
+      g_propagate_error (error, tmp_error);                          \
+      return FALSE;                                                  \
+    }                                                                \
   } G_STMT_END
 
-#define xcf_write_int8_check_error(info, data, count) G_STMT_START {  \
-  info->cp += xcf_write_int8 (info->output, data, count, &tmp_error); \
+#define xcf_write_float_check_error(info, data, count) G_STMT_START { \
+  xcf_write_float (info, data, count, &tmp_error);                    \
   if (tmp_error)                                                      \
     {                                                                 \
       g_propagate_error (error, tmp_error);                           \
@@ -166,8 +175,8 @@ static gboolean xcf_save_vectors       (XcfInfo           *info,
     }                                                                 \
   } G_STMT_END
 
-#define xcf_write_float_check_error(info, data, count) G_STMT_START {  \
-  info->cp += xcf_write_float (info->output, data, count, &tmp_error); \
+#define xcf_write_string_check_error(info, data, count) G_STMT_START { \
+  xcf_write_string (info, data, count, &tmp_error);                    \
   if (tmp_error)                                                       \
     {                                                                  \
       g_propagate_error (error, tmp_error);                            \
@@ -175,23 +184,14 @@ static gboolean xcf_save_vectors       (XcfInfo           *info,
     }                                                                  \
   } G_STMT_END
 
-#define xcf_write_string_check_error(info, data, count) G_STMT_START {  \
-  info->cp += xcf_write_string (info->output, data, count, &tmp_error); \
-  if (tmp_error)                                                        \
-    {                                                                   \
-      g_propagate_error (error, tmp_error);                             \
-      return FALSE;                                                     \
-    }                                                                   \
-  } G_STMT_END
-
 #define xcf_write_prop_type_check_error(info, prop_type) G_STMT_START { \
-  guint32 _prop_int32 = prop_type;                     \
-  xcf_write_int32_check_error (info, &_prop_int32, 1); \
+  guint32 _prop_int32 = prop_type;                                      \
+  xcf_write_int32_check_error (info, &_prop_int32, 1);                  \
   } G_STMT_END
 
 #define xcf_check_error(x) G_STMT_START { \
-  if (! (x))                                                  \
-    return FALSE;                                             \
+  if (! (x))                              \
+    return FALSE;                         \
   } G_STMT_END
 
 #define xcf_progress_update(info) G_STMT_START  \
@@ -1418,9 +1418,9 @@ xcf_save_buffer (XcfInfo     *info,
   height = gegl_buffer_get_height (buffer);
   bpp    = babl_format_get_bytes_per_pixel (format);
 
-  xcf_write_int32_check_error (info, (guint32 *) &width, 1);
+  xcf_write_int32_check_error (info, (guint32 *) &width,  1);
   xcf_write_int32_check_error (info, (guint32 *) &height, 1);
-  xcf_write_int32_check_error (info, (guint32 *) &bpp, 1);
+  xcf_write_int32_check_error (info, (guint32 *) &bpp,    1);
 
   tmp1 = xcf_calc_levels (width,  XCF_TILE_WIDTH);
   tmp2 = xcf_calc_levels (height, XCF_TILE_HEIGHT);
@@ -1502,7 +1502,7 @@ xcf_save_level (XcfInfo     *info,
   height = gegl_buffer_get_height (buffer);
   bpp    = babl_format_get_bytes_per_pixel (format);
 
-  xcf_write_int32_check_error (info, (guint32 *) &width, 1);
+  xcf_write_int32_check_error (info, (guint32 *) &width,  1);
   xcf_write_int32_check_error (info, (guint32 *) &height, 1);
 
   saved_pos = info->cp;
@@ -2103,7 +2103,7 @@ xcf_save_vectors (XcfInfo    *info,
                * [5] wheel (gfloat)
                */
 
-              xcf_write_int32_check_error (info, &type, 1);
+              xcf_write_int32_check_error (info, &type,  1);
               xcf_write_float_check_error (info, coords, num_axes);
             }
 
diff --git a/app/xcf/xcf-write.c b/app/xcf/xcf-write.c
index 5c54331..83ea9b0 100644
--- a/app/xcf/xcf-write.c
+++ b/app/xcf/xcf-write.c
@@ -21,13 +21,16 @@
 
 #include <gio/gio.h>
 
-#include "xcf-write.h"
+#include "core/core-types.h"
 
+#include "xcf-private.h"
+#include "xcf-write.h"
 
 #include "gimp-intl.h"
 
+
 guint
-xcf_write_int32 (GOutputStream  *output,
+xcf_write_int32 (XcfInfo        *info,
                  const guint32  *data,
                  gint            count,
                  GError        **error)
@@ -41,7 +44,7 @@ xcf_write_int32 (GOutputStream  *output,
         {
           guint32  tmp = g_htonl (data[i]);
 
-          xcf_write_int8 (output, (const guint8 *) &tmp, 4, &tmp_error);
+          xcf_write_int8 (info, (const guint8 *) &tmp, 4, &tmp_error);
 
           if (tmp_error)
             {
@@ -56,7 +59,7 @@ xcf_write_int32 (GOutputStream  *output,
 }
 
 guint
-xcf_write_offset (GOutputStream  *output,
+xcf_write_offset (XcfInfo        *info,
                   const goffset  *data,
                   gint            count,
                   GError        **error)
@@ -70,24 +73,24 @@ xcf_write_offset (GOutputStream  *output,
         {
           guint32 tmp = g_htonl (data[i]);
 
-          xcf_write_int8 (output, (const guint8 *) &tmp, 4, &tmp_error);
+          xcf_write_int8 (info, (const guint8 *) &tmp, 4, &tmp_error);
 
           if (tmp_error)
             {
               g_propagate_error (error, tmp_error);
 
-              return i * 4;
+              return i * info->bytes_per_offset;
             }
         }
     }
 
-  return count * 4;
+  return count * info->bytes_per_offset;
 }
 
 guint
-xcf_write_zero_offset (GOutputStream  *output,
-                       gint            count,
-                       GError        **error)
+xcf_write_zero_offset (XcfInfo  *info,
+                       gint      count,
+                       GError  **error)
 {
   if (count > 0)
     {
@@ -95,51 +98,53 @@ xcf_write_zero_offset (GOutputStream  *output,
 
       memset (tmp, 0, count * 4);
 
-      return xcf_write_int8 (output, (const guint8 *) tmp, count * 4, error);
+      return xcf_write_int8 (info, (const guint8 *) tmp, count * 4, error);
     }
 
   return 0;
 }
 
 guint
-xcf_write_float (GOutputStream  *output,
-                 const gfloat   *data,
-                 gint            count,
-                 GError        **error)
+xcf_write_float (XcfInfo       *info,
+                 const gfloat  *data,
+                 gint           count,
+                 GError       **error)
 {
-  return xcf_write_int32 (output,
+  return xcf_write_int32 (info,
                           (const guint32 *)((gconstpointer) data), count,
                           error);
 }
 
 guint
-xcf_write_int8 (GOutputStream  *output,
-                const guint8   *data,
-                gint            count,
-                GError        **error)
+xcf_write_int8 (XcfInfo       *info,
+                const guint8  *data,
+                gint           count,
+                GError       **error)
 {
   GError *my_error = NULL;
   gsize   bytes_written;
 
-  if (! g_output_stream_write_all (output, data, count,
+  if (! g_output_stream_write_all (info->output, data, count,
                                    &bytes_written, NULL, &my_error))
     {
       g_propagate_prefixed_error (error, my_error,
                                   _("Error writing XCF: "));
     }
 
+  info->cp += bytes_written;
+
   return bytes_written;
 }
 
 guint
-xcf_write_string (GOutputStream  *output,
-                  gchar         **data,
-                  gint            count,
-                  GError        **error)
+xcf_write_string (XcfInfo  *info,
+                  gchar   **data,
+                  gint      count,
+                  GError  **error)
 {
-  GError  *tmp_error = NULL;
-  guint    total     = 0;
-  gint     i;
+  GError *tmp_error = NULL;
+  guint   total     = 0;
+  gint    i;
 
   for (i = 0; i < count; i++)
     {
@@ -150,7 +155,7 @@ xcf_write_string (GOutputStream  *output,
       else
         tmp = 0;
 
-      xcf_write_int32 (output, &tmp, 1, &tmp_error);
+      xcf_write_int32 (info, &tmp, 1, &tmp_error);
 
       if (tmp_error)
         {
@@ -159,7 +164,7 @@ xcf_write_string (GOutputStream  *output,
         }
 
       if (tmp > 0)
-        xcf_write_int8 (output, (const guint8 *) data[i], tmp, &tmp_error);
+        xcf_write_int8 (info, (const guint8 *) data[i], tmp, &tmp_error);
 
       if (tmp_error)
         {
diff --git a/app/xcf/xcf-write.h b/app/xcf/xcf-write.h
index 1bb68d5..9913752 100644
--- a/app/xcf/xcf-write.h
+++ b/app/xcf/xcf-write.h
@@ -19,26 +19,26 @@
 #define __XCF_WRITE_H__
 
 
-guint   xcf_write_int32       (GOutputStream  *output,
+guint   xcf_write_int32       (XcfInfo        *info,
                                const guint32  *data,
                                gint            count,
                                GError        **error);
-guint   xcf_write_offset      (GOutputStream  *output,
+guint   xcf_write_offset      (XcfInfo        *info,
                                const goffset  *data,
                                gint            count,
                                GError        **error);
-guint   xcf_write_zero_offset (GOutputStream  *output,
+guint   xcf_write_zero_offset (XcfInfo        *info,
                                gint            count,
                                GError        **error);
-guint   xcf_write_float       (GOutputStream  *output,
+guint   xcf_write_float       (XcfInfo        *info,
                                const gfloat   *data,
                                gint            count,
                                GError        **error);
-guint   xcf_write_int8        (GOutputStream  *output,
+guint   xcf_write_int8        (XcfInfo        *info,
                                const guint8   *data,
                                gint            count,
                                GError        **error);
-guint   xcf_write_string      (GOutputStream  *output,
+guint   xcf_write_string      (XcfInfo        *info,
                                gchar         **data,
                                gint            count,
                                GError        **error);


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