[gimp] plug-ins: improve JPEG and EXR comment validation



commit f7413d70dd27dc64e824d998ba8d067929f08bcf
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jun 26 16:51:26 2019 +0200

    plug-ins: improve JPEG and EXR comment validation
    
    If the comment doesn't UTF-8 validate, leave valid UTF-8 at the
    beginning intact. Also fix character range comparison to use guchar
    instead of gchar

 plug-ins/file-exr/file-exr.c   | 8 +++++---
 plug-ins/file-jpeg/jpeg-load.c | 8 +++++---
 2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/plug-ins/file-exr/file-exr.c b/plug-ins/file-exr/file-exr.c
index c99266f701..cac33cd642 100644
--- a/plug-ins/file-exr/file-exr.c
+++ b/plug-ins/file-exr/file-exr.c
@@ -378,11 +378,13 @@ load_image (const gchar  *filename,
 static void
 sanitize_comment (gchar *comment)
 {
-  if (! g_utf8_validate (comment, -1, NULL))
+  const gchar *start_invalid;
+
+  if (! g_utf8_validate (comment, -1, &start_invalid))
     {
-      gchar *c;
+      guchar *c;
 
-      for (c = comment; *c; c++)
+      for (c = (guchar *) start_invalid; *c; c++)
         {
           if (*c > 126 || (*c < 32 && *c != '\t' && *c != '\n' && *c != '\r'))
             *c = '?';
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index c3e16b7558..aefa7c2438 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -495,11 +495,13 @@ jpeg_load_resolution (gint32                         image_ID,
 static void
 jpeg_load_sanitize_comment (gchar *comment)
 {
-  if (! g_utf8_validate (comment, -1, NULL))
+  const gchar *start_invalid;
+
+  if (! g_utf8_validate (comment, -1, &start_invalid))
     {
-      gchar *c;
+      guchar *c;
 
-      for (c = comment; *c; c++)
+      for (c = (guchar *) start_invalid; *c; c++)
         {
           if (*c > 126 || (*c < 32 && *c != '\t' && *c != '\n' && *c != '\r'))
             *c = '?';


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