2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-07-09 13:31:06 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp_brush_generated module Copyright 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-07-09 13:31:06 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-07-09 13:31:06 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-07-09 13:31:06 +08:00
|
|
|
*/
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
#include <stdlib.h>
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2004-01-19 09:54:11 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
#include "gimp-utils.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpbrushgenerated.h"
|
2006-10-03 20:29:07 +08:00
|
|
|
#include "gimpbrushgenerated-load.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2004-07-27 03:00:22 +08:00
|
|
|
GList *
|
2014-07-04 09:31:03 +08:00
|
|
|
gimp_brush_generated_load (GimpContext *context,
|
|
|
|
GFile *file,
|
|
|
|
GInputStream *input,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2005-11-01 22:41:41 +08:00
|
|
|
GimpBrush *brush;
|
2014-07-03 03:33:00 +08:00
|
|
|
GDataInputStream *data_input;
|
|
|
|
gchar *string;
|
|
|
|
gsize string_len;
|
2006-10-05 01:50:35 +08:00
|
|
|
gint linenum;
|
2004-08-10 19:33:13 +08:00
|
|
|
gchar *name = NULL;
|
|
|
|
GimpBrushGeneratedShape shape = GIMP_BRUSH_GENERATED_CIRCLE;
|
2004-08-01 11:06:58 +08:00
|
|
|
gboolean have_shape = FALSE;
|
2004-08-10 19:33:13 +08:00
|
|
|
gint spikes = 2;
|
2004-08-01 11:06:58 +08:00
|
|
|
gdouble spacing;
|
|
|
|
gdouble radius;
|
|
|
|
gdouble hardness;
|
|
|
|
gdouble aspect_ratio;
|
|
|
|
gdouble angle;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-01 08:30:22 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2014-07-04 09:31:03 +08:00
|
|
|
g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
|
2014-07-01 08:30:22 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2004-01-30 00:19:57 +08:00
|
|
|
|
2014-07-04 09:31:03 +08:00
|
|
|
data_input = g_data_input_stream_new (input);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* make sure the file we are reading is the right type */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum = 1;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (! g_str_has_prefix (string, "GIMP-VBR"))
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2014-07-05 00:46:02 +08:00
|
|
|
_("Not a GIMP brush file."));
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2004-08-10 19:33:13 +08:00
|
|
|
goto failed;
|
2002-12-02 21:39:09 +08:00
|
|
|
}
|
2001-02-14 22:57:14 +08:00
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* make sure we are reading a compatible version */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (! g_str_has_prefix (string, "1.0"))
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
2006-11-13 04:30:50 +08:00
|
|
|
if (! g_str_has_prefix (string, "1.5"))
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2014-07-05 00:46:02 +08:00
|
|
|
_("Unknown GIMP brush version."));
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2004-08-10 19:33:13 +08:00
|
|
|
goto failed;
|
2004-08-01 11:06:58 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
have_shape = TRUE;
|
|
|
|
}
|
2002-12-02 21:39:09 +08:00
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
|
|
|
|
2004-01-30 00:19:57 +08:00
|
|
|
/* read name */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
g_strstrip (string);
|
2006-05-29 23:43:05 +08:00
|
|
|
|
|
|
|
/* the empty string is not an allowed name */
|
|
|
|
if (strlen (string) < 1)
|
2014-08-16 05:08:42 +08:00
|
|
|
{
|
|
|
|
name = g_strdup (_("Untitled"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name = gimp_any_to_utf8 (string, -1,
|
|
|
|
_("Invalid UTF-8 string in brush file '%s'."),
|
|
|
|
gimp_file_get_utf8_name (file));
|
|
|
|
}
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
if (have_shape)
|
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *shape_val;
|
|
|
|
|
|
|
|
enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);
|
|
|
|
|
|
|
|
/* read shape */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-08-01 11:06:58 +08:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
g_strstrip (string);
|
|
|
|
shape_val = g_enum_get_value_by_nick (enum_class, string);
|
|
|
|
|
2006-10-05 01:50:35 +08:00
|
|
|
if (! shape_val)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
2014-07-05 00:46:02 +08:00
|
|
|
_("Unknown GIMP brush shape."));
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2004-08-10 19:33:13 +08:00
|
|
|
goto failed;
|
2004-08-01 11:06:58 +08:00
|
|
|
}
|
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
|
|
|
|
2004-08-01 11:06:58 +08:00
|
|
|
shape = shape_val->value;
|
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* read brush spacing */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtod (string, NULL, &spacing))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush spacing."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* read brush radius */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtod (string, NULL, &radius))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush radius."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
if (have_shape)
|
|
|
|
{
|
2006-10-05 01:50:35 +08:00
|
|
|
/* read number of spikes */
|
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-08-02 01:20:00 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtoi (string, NULL, 10, &spikes) ||
|
|
|
|
spikes < 2 || spikes > 20)
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush spike count."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2004-08-02 01:20:00 +08:00
|
|
|
}
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
/* read brush hardness */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtod (string, NULL, &hardness))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush hardness."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush aspect_ratio */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtod (string, NULL, &aspect_ratio))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush aspect ratio."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
|
|
|
/* read brush angle */
|
2006-10-05 01:50:35 +08:00
|
|
|
linenum++;
|
2014-07-03 03:33:00 +08:00
|
|
|
string_len = 256;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
string = gimp_data_input_stream_read_line_always (data_input, &string_len,
|
|
|
|
NULL, error);
|
2014-07-03 03:33:00 +08:00
|
|
|
if (! string)
|
2004-06-25 21:41:24 +08:00
|
|
|
goto failed;
|
Issue #1682 - Segfault when starting GIMP, due to empty data files
Use gimp_input_data_stream_read_line_always(), instead of
g_input_data_stream_read_line(), in a bunch of places that don't
expect EOF. If we don't do that, the code assumes the GError
parameter is set by the function and returns an error indication,
causing the caller to segfault when it tries to access
error->message. Instead, we now process an empty line when EOF is
reached, which is caught by the normal parsing logic.
Additionally:
- Use gimp_ascii_strto[id]() when loading gradients, generated
brushes, and palettes, to improve error checking for invalid
numeric input.
- Improve gradient-segment endpoint consistency check.
- Allow loading palette files with 0 colors. They can be created
during the session, so we might as well successfully load them.
2018-06-21 02:47:15 +08:00
|
|
|
if (! gimp_ascii_strtod (string, NULL, &angle))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
|
|
|
|
_("Invalid brush angle."));
|
|
|
|
g_free (string);
|
|
|
|
goto failed;
|
|
|
|
}
|
2014-07-03 03:33:00 +08:00
|
|
|
g_free (string);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_object_unref (data_input);
|
2001-02-11 09:39:24 +08:00
|
|
|
|
2005-11-01 22:41:41 +08:00
|
|
|
brush = GIMP_BRUSH (gimp_brush_generated_new (name, shape, radius, spikes,
|
|
|
|
hardness, aspect_ratio, angle));
|
2004-06-25 21:41:24 +08:00
|
|
|
g_free (name);
|
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
gimp_brush_set_spacing (brush, spacing);
|
2004-06-25 21:41:24 +08:00
|
|
|
|
2004-07-27 03:00:22 +08:00
|
|
|
return g_list_prepend (NULL, brush);
|
2004-06-25 21:41:24 +08:00
|
|
|
|
|
|
|
failed:
|
|
|
|
|
2014-07-03 03:33:00 +08:00
|
|
|
g_object_unref (data_input);
|
2004-08-10 10:37:44 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
if (name)
|
|
|
|
g_free (name);
|
|
|
|
|
2014-07-05 00:46:02 +08:00
|
|
|
g_prefix_error (error, _("In line %d of brush file: "), linenum);
|
2014-07-03 21:47:57 +08:00
|
|
|
|
2004-06-25 21:41:24 +08:00
|
|
|
return NULL;
|
2001-02-11 09:39:24 +08:00
|
|
|
}
|