babl: re-creation of palette conversions must always set data.
authorJehan <jehan@girinstud.io>
Wed, 3 Mar 2021 10:03:38 +0000 (11:03 +0100)
committerØyvind "pippin" Kolås <pippin@gimp.org>
Sat, 15 May 2021 20:57:03 +0000 (20:57 +0000)
If we allow conversions to be recreated for palettes, it will create a
new identical conversion with collision number incremented in the name
and no user data. Yet the user data is extremely important for palette
conversions, because it contains the palette itself which is required by
the palette conversion functions. Hence we end up crashing.

Moreover, although I think that right now, only palette conversions use
the data field, it might be used for other type of data in the future.
In any case, we should always save this data along as it has been stored
there for a reason.

Finally in babl-palette code, make sure the user data is added to the
models before creating the formats and conversions as we also ended up
in crash-happy code when we didn't.

See: https://gitlab.gnome.org/GNOME/gimp/-/issues/6501

babl/babl-fish-path.c
babl/babl-palette.c

index b0396dbcb11209fc6d7ab871fae394ed86673413..32da078e9b41f27daf76d65b18b1dc3999e87b97 100644 (file)
@@ -406,6 +406,7 @@ alias_conversion (Babl *babl,
                 babl_remodel_with_space (
                       (void*)conv->destination, (void*)space),
                 "linear", conv->function.linear,
+                "data",   conv->data,
                 NULL);
           break;
         case BABL_CONVERSION_PLANAR:
@@ -415,6 +416,7 @@ alias_conversion (Babl *babl,
                 babl_remodel_with_space (
                       (void*)conv->destination, (void*)space),
                 "planar", conv->function.planar,
+                "data",   conv->data,
                 NULL);
           break;
         case BABL_CONVERSION_PLANE:
@@ -424,6 +426,7 @@ alias_conversion (Babl *babl,
                 babl_remodel_with_space (
                       (void*)conv->destination, (void*)space),
                 "plane", conv->function.plane,
+                "data",  conv->data,
                 NULL);
           break;
         default:
index 086da675d19b8bb85b543c32b7127b8c1de90495..1db8facd95fc0e60a13cf0e421848a7248f7f9bb 100644 (file)
@@ -831,6 +831,10 @@ babl_new_palette_with_space (const char  *name,
   *palptr = default_palette ();;
   cname[0] = 'v';
   model_no_alpha = babl_model_new ("name", name, component, NULL);
+
+  babl_set_user_data (model, palptr);
+  babl_set_user_data (model_no_alpha, palptr);
+
   cname[0] = '\\';
   f_pal_a_u8 = (void*) babl_format_new ("name", name, model, space,
                                 babl_type ("u8"),
@@ -924,9 +928,6 @@ babl_new_palette_with_space (const char  *name,
      "data", palptr,
      NULL);
 
-  babl_set_user_data (model, palptr);
-  babl_set_user_data (model_no_alpha, palptr);
-
   if (format_u8)
     *format_u8 = f_pal_u8;
   if (format_u8_with_alpha)