Commit 2ac529cb authored by Ell's avatar Ell

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 a0a62656)
parent e25cccf0
......@@ -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,
......
......@@ -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,
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment