libgimp, plug-ins: Prevent GFig crash with NULL brush

The GFig plug-in assumes that there is always
a valid brush selected when creating its
dialogue. However, a NULL brush is possible,
and GFig's assumption can cause a crash
in GIMP by attempting to get a buffer from
a NULL brush.
This patch adds conditional checks for the
brush to not be NULL before using it.
This commit is contained in:
Alx Sa 2025-05-05 09:36:04 +00:00
parent 373e46f871
commit 2c31c0e34d
5 changed files with 54 additions and 28 deletions

View file

@ -162,19 +162,22 @@ brush_get_info_invoker (GimpProcedure *procedure,
{ {
GimpTempBuf *mask = gimp_brush_get_mask (brush); GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush); GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
const Babl *format; const Babl *format = NULL;
format = gimp_babl_compat_u8_mask_format ( if (brush)
gimp_temp_buf_get_format (mask)); format = gimp_babl_compat_u8_mask_format (gimp_temp_buf_get_format (mask));
width = gimp_brush_get_width (brush); width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush); height = gimp_brush_get_height (brush);
mask_bpp = babl_format_get_bytes_per_pixel (format);
if (pixmap) if (format)
mask_bpp = babl_format_get_bytes_per_pixel (format);
else
mask_bpp = 0;
if (pixmap && format)
{ {
format = gimp_babl_compat_u8_format ( format = gimp_babl_compat_u8_format (gimp_temp_buf_get_format (pixmap));
gimp_temp_buf_get_format (pixmap));
color_bpp = babl_format_get_bytes_per_pixel (format); color_bpp = babl_format_get_bytes_per_pixel (format);
} }

View file

@ -217,6 +217,8 @@ gimp_brush_chooser_get_brush_bitmap (GimpBrushChooser *chooser,
GimpBrush *brush; GimpBrush *brush;
g_object_get (chooser, "resource", &brush, NULL); g_object_get (chooser, "resource", &brush, NULL);
if (! brush)
return;
if (chooser->brush == brush && if (chooser->brush == brush &&
chooser->width == width && chooser->width == width &&

View file

@ -138,19 +138,22 @@ HELP
{ {
GimpTempBuf *mask = gimp_brush_get_mask (brush); GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush); GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
const Babl *format; const Babl *format = NULL;
format = gimp_babl_compat_u8_mask_format ( if (brush)
gimp_temp_buf_get_format (mask)); format = gimp_babl_compat_u8_mask_format (gimp_temp_buf_get_format (mask));
width = gimp_brush_get_width (brush); width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush); height = gimp_brush_get_height (brush);
mask_bpp = babl_format_get_bytes_per_pixel (format);
if (pixmap) if (format)
mask_bpp = babl_format_get_bytes_per_pixel (format);
else
mask_bpp = 0;
if (pixmap && format)
{ {
format = gimp_babl_compat_u8_format ( format = gimp_babl_compat_u8_format (gimp_temp_buf_get_format (pixmap));
gimp_temp_buf_get_format (pixmap));
color_bpp = babl_format_get_bytes_per_pixel (format); color_bpp = babl_format_get_bytes_per_pixel (format);
} }

View file

@ -630,6 +630,7 @@ gfig_dialog (GimpGfig *gfig)
gfig_list_load_all (gfig_path); gfig_list_load_all (gfig_path);
/* Setup initial brush settings */ /* Setup initial brush settings */
if (gimp_context_get_brush ())
set_context_bdesc (gimp_context_get_brush ()); set_context_bdesc (gimp_context_get_brush ());
gtk_widget_show (main_hbox); gtk_widget_show (main_hbox);

View file

@ -533,6 +533,7 @@ gfig_brush_changed_callback (gpointer user_data,
current_style->brush = brush; current_style->brush = brush;
/* this will soon be unneeded. How soon? */ /* this will soon be unneeded. How soon? */
if (brush)
set_context_bdesc (brush); set_context_bdesc (brush);
gimp_context_set_brush (brush); gimp_context_set_brush (brush);
@ -660,6 +661,8 @@ gfig_read_gimp_style (Style *style,
style->fill_opacity = 100.; style->fill_opacity = 100.;
/* Cache attributes of brush. */ /* Cache attributes of brush. */
if (style->brush)
{
gimp_brush_get_info (style->brush, gimp_brush_get_info (style->brush,
&style->brush_width, &style->brush_height, &style->brush_width, &style->brush_height,
&dummy, &dummy); &dummy, &dummy);
@ -667,6 +670,16 @@ gfig_read_gimp_style (Style *style,
set_context_bdesc (style->brush); set_context_bdesc (style->brush);
} }
else
{
style->brush_width = 1;
style->brush_height = 1;
style->brush_spacing = 1;
gfig_context->bdesc.width = 48;
gfig_context->bdesc.height = 48;
}
}
/* /*
* gfig_style_set_content_from_style() sets all of the style control widgets * gfig_style_set_content_from_style() sets all of the style control widgets
@ -695,15 +708,19 @@ gfig_style_set_context_from_style (Style *style)
gimp_context_set_brush_default_size (); gimp_context_set_brush_default_size ();
if (style->brush)
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->brush_select), gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->brush_select),
GIMP_RESOURCE (style->brush)); GIMP_RESOURCE (style->brush));
if (style->pattern)
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->pattern_select), gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->pattern_select),
GIMP_RESOURCE (style->pattern)); GIMP_RESOURCE (style->pattern));
if (style->gradient)
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->gradient_select), gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->gradient_select),
GIMP_RESOURCE (style->gradient)); GIMP_RESOURCE (style->gradient));
if (style->brush)
set_context_bdesc (style->brush); set_context_bdesc (style->brush);
if (gfig_context->debug_styles) if (gfig_context->debug_styles)