[gimp/gimp-2-10] Issue #1792 - Xcf file crashing gimp-console-2.10 ...
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] Issue #1792 - Xcf file crashing gimp-console-2.10 ...
- Date: Fri, 6 Jul 2018 17:07:56 +0000 (UTC)
commit 2ac529cb8ccdcbcedf949036702b1fd81719eb91
Author: Ell <ell_se yahoo com>
Date: Fri Jul 6 13:00:35 2018 -0400
Issue #1792 - Xcf file crashing gimp-console-2.10 ...
... (valgrind reports Invalid read)
Add gimp_babl_is_valid(), which takes a GimpImageBaseType and a
GimpPrecision, and determines whether the image-type/precision
combination is valid. Use this function to validate that loaded
XCFs use a valid type/precision combination, before trying to
create the image. Otherwise, we get a CRITICAL, and eventually a
segfault, when the combination is invalid.
Use the same function to validate the arguments of
gimp_image_new().
(cherry picked from commit a0a62656d2d562649414bb4f93d58bda52d7157b)
app/core/gimpimage.c | 3 +--
app/gegl/gimp-babl.c | 24 ++++++++++++++++++++++++
app/gegl/gimp-babl.h | 3 +++
app/xcf/xcf-load.c | 9 +++++++++
4 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 7f89c48900..1f09c89f57 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1703,8 +1703,7 @@ gimp_image_new (Gimp *gimp,
GimpPrecision precision)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
- g_return_val_if_fail (base_type != GIMP_INDEXED ||
- precision == GIMP_PRECISION_U8_GAMMA, NULL);
+ g_return_val_if_fail (gimp_babl_is_valid (base_type, precision), NULL);
return g_object_new (GIMP_TYPE_IMAGE,
"gimp", gimp,
diff --git a/app/gegl/gimp-babl.c b/app/gegl/gimp-babl.c
index 129d53e265..a2093cb401 100644
--- a/app/gegl/gimp-babl.c
+++ b/app/gegl/gimp-babl.c
@@ -755,6 +755,30 @@ gimp_babl_precision (GimpComponentType component,
g_return_val_if_reached (-1);
}
+gboolean
+gimp_babl_is_valid (GimpImageBaseType base_type,
+ GimpPrecision precision)
+{
+ switch (base_type)
+ {
+ case GIMP_RGB:
+ case GIMP_GRAY:
+ return TRUE;
+
+ case GIMP_INDEXED:
+ switch (precision)
+ {
+ case GIMP_PRECISION_U8_GAMMA:
+ return TRUE;
+
+ default:
+ return FALSE;
+ }
+ }
+
+ g_return_val_if_reached (FALSE);
+}
+
const Babl *
gimp_babl_format (GimpImageBaseType base_type,
GimpPrecision precision,
diff --git a/app/gegl/gimp-babl.h b/app/gegl/gimp-babl.h
index 7a9e1c30a8..2fe6ba6f0f 100644
--- a/app/gegl/gimp-babl.h
+++ b/app/gegl/gimp-babl.h
@@ -38,6 +38,9 @@ gboolean gimp_babl_linear (GimpPrecision precision);
GimpPrecision gimp_babl_precision (GimpComponentType component,
gboolean linear);
+gboolean gimp_babl_is_valid (GimpImageBaseType base_type,
+ GimpPrecision precision);
+
const Babl * gimp_babl_format (GimpImageBaseType base_type,
GimpPrecision precision,
gboolean with_alpha);
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 3f15ca127a..b5ffc06cec 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -31,6 +31,7 @@
#include "config/gimpcoreconfig.h"
+#include "gegl/gimp-babl.h"
#include "gegl/gimp-gegl-tile-compat.h"
#include "core/gimp.h"
@@ -220,6 +221,14 @@ xcf_load_image (Gimp *gimp,
GIMP_LOG (XCF, "version=%d, width=%d, height=%d, image_type=%d, precision=%d",
info->file_version, width, height, image_type, precision);
+ if (! gimp_babl_is_valid (image_type, precision))
+ {
+ gimp_message_literal (gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_ERROR,
+ _("Invalid image mode and precision combination."));
+ goto hard_error;
+ }
+
image = gimp_create_image (gimp, width, height, image_type, precision,
FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]