mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 09:23:24 +00:00
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:
parent
373e46f871
commit
2c31c0e34d
5 changed files with 54 additions and 28 deletions
|
@ -162,19 +162,22 @@ brush_get_info_invoker (GimpProcedure *procedure,
|
|||
{
|
||||
GimpTempBuf *mask = gimp_brush_get_mask (brush);
|
||||
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
|
||||
const Babl *format;
|
||||
const Babl *format = NULL;
|
||||
|
||||
format = gimp_babl_compat_u8_mask_format (
|
||||
gimp_temp_buf_get_format (mask));
|
||||
if (brush)
|
||||
format = gimp_babl_compat_u8_mask_format (gimp_temp_buf_get_format (mask));
|
||||
|
||||
width = gimp_brush_get_width (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 (
|
||||
gimp_temp_buf_get_format (pixmap));
|
||||
format = gimp_babl_compat_u8_format (gimp_temp_buf_get_format (pixmap));
|
||||
|
||||
color_bpp = babl_format_get_bytes_per_pixel (format);
|
||||
}
|
||||
|
|
|
@ -217,6 +217,8 @@ gimp_brush_chooser_get_brush_bitmap (GimpBrushChooser *chooser,
|
|||
GimpBrush *brush;
|
||||
|
||||
g_object_get (chooser, "resource", &brush, NULL);
|
||||
if (! brush)
|
||||
return;
|
||||
|
||||
if (chooser->brush == brush &&
|
||||
chooser->width == width &&
|
||||
|
|
|
@ -138,19 +138,22 @@ HELP
|
|||
{
|
||||
GimpTempBuf *mask = gimp_brush_get_mask (brush);
|
||||
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
|
||||
const Babl *format;
|
||||
const Babl *format = NULL;
|
||||
|
||||
format = gimp_babl_compat_u8_mask_format (
|
||||
gimp_temp_buf_get_format (mask));
|
||||
if (brush)
|
||||
format = gimp_babl_compat_u8_mask_format (gimp_temp_buf_get_format (mask));
|
||||
|
||||
width = gimp_brush_get_width (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 (
|
||||
gimp_temp_buf_get_format (pixmap));
|
||||
format = gimp_babl_compat_u8_format (gimp_temp_buf_get_format (pixmap));
|
||||
|
||||
color_bpp = babl_format_get_bytes_per_pixel (format);
|
||||
}
|
||||
|
|
|
@ -630,7 +630,8 @@ gfig_dialog (GimpGfig *gfig)
|
|||
gfig_list_load_all (gfig_path);
|
||||
|
||||
/* Setup initial brush settings */
|
||||
set_context_bdesc (gimp_context_get_brush ());
|
||||
if (gimp_context_get_brush ())
|
||||
set_context_bdesc (gimp_context_get_brush ());
|
||||
|
||||
gtk_widget_show (main_hbox);
|
||||
|
||||
|
|
|
@ -533,7 +533,8 @@ gfig_brush_changed_callback (gpointer user_data,
|
|||
current_style->brush = brush;
|
||||
|
||||
/* this will soon be unneeded. How soon? */
|
||||
set_context_bdesc (brush);
|
||||
if (brush)
|
||||
set_context_bdesc (brush);
|
||||
|
||||
gimp_context_set_brush (brush);
|
||||
gimp_context_set_brush_default_size ();
|
||||
|
@ -660,12 +661,24 @@ gfig_read_gimp_style (Style *style,
|
|||
style->fill_opacity = 100.;
|
||||
|
||||
/* Cache attributes of brush. */
|
||||
gimp_brush_get_info (style->brush,
|
||||
&style->brush_width, &style->brush_height,
|
||||
&dummy, &dummy);
|
||||
style->brush_spacing = gimp_brush_get_spacing (style->brush);
|
||||
if (style->brush)
|
||||
{
|
||||
gimp_brush_get_info (style->brush,
|
||||
&style->brush_width, &style->brush_height,
|
||||
&dummy, &dummy);
|
||||
style->brush_spacing = gimp_brush_get_spacing (style->brush);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -695,16 +708,20 @@ gfig_style_set_context_from_style (Style *style)
|
|||
|
||||
gimp_context_set_brush_default_size ();
|
||||
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->brush_select),
|
||||
GIMP_RESOURCE (style->brush));
|
||||
if (style->brush)
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->brush_select),
|
||||
GIMP_RESOURCE (style->brush));
|
||||
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->pattern_select),
|
||||
GIMP_RESOURCE (style->pattern));
|
||||
if (style->pattern)
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->pattern_select),
|
||||
GIMP_RESOURCE (style->pattern));
|
||||
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->gradient_select),
|
||||
GIMP_RESOURCE (style->gradient));
|
||||
if (style->gradient)
|
||||
gimp_resource_chooser_set_resource (GIMP_RESOURCE_CHOOSER (gfig_context->gradient_select),
|
||||
GIMP_RESOURCE (style->gradient));
|
||||
|
||||
set_context_bdesc (style->brush);
|
||||
if (style->brush)
|
||||
set_context_bdesc (style->brush);
|
||||
|
||||
if (gfig_context->debug_styles)
|
||||
g_printerr ("done.\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue