From 62da36cd4391cf3507671604065358f46a378a98 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Fri, 24 Nov 2023 06:08:09 +0000 Subject: [PATCH] core: Better handle group endings in ASE palette import This patch adds better handling for group begin and end markers within ASE palettes. As a result, this fixes an issue where the last color was not imported in some ASE files without groups. Additionally, this guarantees that colors are imported using 4 bytes per https://gitlab.gnome.org/GNOME/gimp/-/issues/10359#note_1921462 --- app/core/gimppalette-load.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/core/gimppalette-load.c b/app/core/gimppalette-load.c index 6cc3112d37..8695fe3c6d 100644 --- a/app/core/gimppalette-load.c +++ b/app/core/gimppalette-load.c @@ -1079,9 +1079,6 @@ gimp_palette_load_ase (GimpContext *context, } g_free (palette_name); - /* Header blocks are considered a "color" so we offset the count here */ - num_cols -= 1; - for (i = 0; i < num_cols; i++) { gchar color_space[4]; @@ -1104,6 +1101,23 @@ gimp_palette_load_ase (GimpContext *context, } skip_first = FALSE; + /* Skip group marker padding */ + group = GINT16_FROM_BE (group); + if (group < 0) + { + gchar marker[4]; + + if (! g_input_stream_read_all (input, &marker, sizeof (marker), + &bytes_read, NULL, error)) + { + g_printerr ("Invalid ASE group marker: %s.", + gimp_file_get_utf8_name (file)); + break; + } + num_cols--; + continue; + } + color_name = gimp_palette_load_ase_block_name (input, file_size, error); if (! color_name) break; @@ -1144,7 +1158,7 @@ gimp_palette_load_ase (GimpContext *context, for (gint j = 0; j < components; j++) { - gint tmp; + gint32 tmp; if (! g_input_stream_read_all (input, &tmp, sizeof (tmp), &bytes_read, NULL, error))