[gimp/gimp-2-8] Bug 731384 - Truncated abr files causing Gimp to not load/crash



commit fc0a0b828b68944aea521e41d776a94cd496c80e
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 24 16:35:32 2014 +0200

    Bug 731384 - Truncated abr files causing Gimp to not load/crash
    
    Add some feof() checks in the ABR brush loaders and error out on
    truncated files. This is by far not as good as in master, but at least
    should prevent the crashes on lots of truncated files.

 app/core/gimpbrush-load.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c
index e7c353b..f76c35a 100644
--- a/app/core/gimpbrush-load.c
+++ b/app/core/gimpbrush-load.c
@@ -620,6 +620,15 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
 
         abr_sampled_brush_hdr.depth = abr_read_short (file);
 
+        if (feof (file))
+          {
+            g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
+                         _("Fatal parse error in brush file '%s': "
+                           "File appears truncated."),
+                         gimp_filename_to_utf8 (filename));
+            return NULL;
+          }
+
         height = (abr_sampled_brush_hdr.bounds_long[2] -
                   abr_sampled_brush_hdr.bounds_long[0]); /* bottom - top */
         width  = (abr_sampled_brush_hdr.bounds_long[3] -
@@ -684,6 +693,16 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
           fread (mask, size, 1, file);
         else
           abr_rle_decode (file, (gchar *) mask, height);
+
+        if (feof (file))
+          {
+            g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
+                         _("Fatal parse error in brush file '%s': "
+                           "File appears truncated."),
+                         gimp_filename_to_utf8 (filename));
+            g_object_unref (brush);
+            return NULL;
+          }
       }
       break;
 
@@ -754,6 +773,15 @@ gimp_brush_load_abr_brush_v6 (FILE         *file,
   depth    = abr_read_short (file);
   compress = abr_read_char (file);
 
+  if (feof (file))
+    {
+      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
+                   _("Fatal parse error in brush file '%s': "
+                     "File appears truncated."),
+                   gimp_filename_to_utf8 (filename));
+      return NULL;
+    }
+
   width  = right - left;
   height = bottom - top;
   size   = width * (depth >> 3) * height;
@@ -788,6 +816,16 @@ gimp_brush_load_abr_brush_v6 (FILE         *file,
 
   fseek (file, next_brush, SEEK_SET);
 
+  if (feof (file))
+    {
+      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
+                   _("Fatal parse error in brush file '%s': "
+                     "File appears truncated."),
+                   gimp_filename_to_utf8 (filename));
+      g_object_unref (brush);
+      return NULL;
+    }
+
   return brush;
 }
 


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