[gimp/gimp-2.10] Issue #8505: WEBP, be more informative with error.



commit cdb14671057cf8fbe0290e2a784c14af5b274fa0
Author: Jehan <jehan girinstud io>
Date:   Fri Aug 19 13:36:38 2022 +0200

    Issue #8505: WEBP, be more informative with error.
    
    Add the info about max dimension of WebP with WEBP_MAX_DIMENSION macro.
    
    There is also a test about (picture->width / 4 > INT_MAX / 4), resp.
    height, but this should anyway never happen as the C spec says the
    smaller range for int is [-32767, 32767], which is an order bigger than
    the current WEBP_MAX_DIMENSION (16383).
    So we are probably fine assuming all VP8_ENC_ERROR_BAD_DIMENSION errors
    will happen because of WEBP_MAX_DIMENSION.
    
    (cherry picked from commit dfb7d2543a9d5ba0ca9ae070c1de95ebc962a89d)

 plug-ins/file-webp/file-webp-save.c | 46 +++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 20 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index 5aaa383735..51dffd90ee 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -50,7 +50,7 @@ int           webp_file_writer      (const uint8_t     *data,
                                      const WebPPicture *picture);
 int           webp_file_progress    (int                percent,
                                      const WebPPicture *picture);
-const gchar * webp_error_string     (WebPEncodingError  error_code);
+gchar *       webp_error_string     (WebPEncodingError  error_code);
 
 gboolean      save_layer            (const gchar       *filename,
                                      gint32             nLayers,
@@ -107,35 +107,37 @@ webp_file_progress (int                percent,
   return gimp_progress_update (percent / 100.0);
 }
 
-const gchar *
+gchar *
 webp_error_string (WebPEncodingError error_code)
 {
   switch (error_code)
     {
     case VP8_ENC_ERROR_OUT_OF_MEMORY:
-      return _("out of memory");
+      return g_strdup (_("out of memory"));
     case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
-      return _("not enough memory to flush bits");
+      return g_strdup (_("not enough memory to flush bits"));
     case VP8_ENC_ERROR_NULL_PARAMETER:
-      return _("NULL parameter");
+      return g_strdup (_("NULL parameter"));
     case VP8_ENC_ERROR_INVALID_CONFIGURATION:
-      return _("invalid configuration");
+      return g_strdup (_("invalid configuration"));
     case VP8_ENC_ERROR_BAD_DIMENSION:
-      return _("bad image dimensions");
+      /* TRANSLATORS: widthxheight with UTF-8 encoded multiply sign. */
+      return g_strdup_printf (_("bad image dimensions (maximum: %d\xc3\x97%d)"),
+                              WEBP_MAX_DIMENSION, WEBP_MAX_DIMENSION);
     case VP8_ENC_ERROR_PARTITION0_OVERFLOW:
-      return _("partition is bigger than 512K");
+      return g_strdup (_("partition is bigger than 512K"));
     case VP8_ENC_ERROR_PARTITION_OVERFLOW:
-      return _("partition is bigger than 16M");
+      return g_strdup (_("partition is bigger than 16M"));
     case VP8_ENC_ERROR_BAD_WRITE:
-      return _("unable to flush bytes");
+      return g_strdup (_("unable to flush bytes"));
     case VP8_ENC_ERROR_FILE_TOO_BIG:
-      return _("file is larger than 4GiB");
+      return g_strdup (_("file is larger than 4GiB"));
     case VP8_ENC_ERROR_USER_ABORT:
-      return _("user aborted encoding");
+      return g_strdup (_("user aborted encoding"));
     case VP8_ENC_ERROR_LAST:
-      return _("list terminator");
+      return g_strdup (_("list terminator"));
     default:
-      return _("unknown error");
+      return g_strdup (_("unknown error"));
     }
 }
 
@@ -264,12 +266,14 @@ save_layer (const gchar    *filename,
       /* Perform the actual encode */
       if (! WebPEncode (&config, &picture))
         {
-          g_printerr ("WebP error: '%s'",
-                      webp_error_string (picture.error_code));
+          gchar *error_str = webp_error_string (picture.error_code);
+
+          g_printerr ("WebP error: '%s'", error_str);
           g_set_error (error, G_FILE_ERROR,
                        picture.error_code,
                        _("WebP error: '%s'"),
-                       webp_error_string (picture.error_code));
+                       error_str);
+          g_free (error_str);
           status = FALSE;
           break;
         }
@@ -678,9 +682,11 @@ save_animation (const gchar    *filename,
           /* Perform the actual encode */
           else if (! WebPAnimEncoderAdd (enc, &picture, frame_timestamp, &config))
             {
-              g_printerr ("ERROR[%d]: %s\n",
-                          picture.error_code,
-                          webp_error_string (picture.error_code));
+              gchar *error_str = webp_error_string (picture.error_code);
+              g_printerr ("ERROR[%d]: line %d: %s\n",
+                          picture.error_code, __LINE__,
+                          error_str);
+              g_free (error_str);
               status = FALSE;
             }
 


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