[gimp/gimp-2-8] Bug 704118 - crash on invalid number of PLTE entries
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-8] Bug 704118 - crash on invalid number of PLTE entries
- Date: Sun, 14 Jul 2013 20:40:18 +0000 (UTC)
commit a1cd4144dffb3f183249b2af17efed6ad11aa6ad
Author: Michael Natterer <mitch gimp org>
Date: Sun Jul 14 22:25:44 2013 +0200
Bug 704118 - crash on invalid number of PLTE entries
Make sure an indexed image always has a colormap. This was the case
before, except one could set a NULL colormap via the PDB.
Add gimp_image_unset_colormap(), and make gimp_image_set_colormap()
never set the colormap to NULL, even if NULL is passed. Change the
only places where actual unsetting makes sense to use unset().
Make some GUI places deal gracefully with palettes/colormaps with zero
entries.
(cherry picked from commit 37372555e5820f7f0c3a98ce9975ef66c2d8422c)
app/actions/colormap-actions.c | 2 +-
app/core/gimpimage-colormap.c | 36 ++++++++++++++++++++++++++++--------
app/core/gimpimage-colormap.h | 2 ++
app/core/gimpimage-convert.c | 2 +-
app/core/gimpimageundo.c | 9 ++++++---
app/widgets/gimppaletteview.c | 2 +-
6 files changed, 39 insertions(+), 14 deletions(-)
---
diff --git a/app/actions/colormap-actions.c b/app/actions/colormap-actions.c
index 6cd2ead..0dcda8d 100644
--- a/app/actions/colormap-actions.c
+++ b/app/actions/colormap-actions.c
@@ -109,7 +109,7 @@ colormap_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_color (group, action, color, FALSE);
SET_SENSITIVE ("colormap-edit-color",
- image && indexed);
+ image && indexed && num_colors > 0);
SET_SENSITIVE ("colormap-add-color-from-fg",
image && indexed && num_colors < 256);
SET_SENSITIVE ("colormap-add-color-from-bg",
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index 0a0e7e5..e2e0ea8 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -40,8 +40,8 @@
/* local function prototype */
-void gimp_image_colormap_set_palette_entry (GimpImage *image,
- gint index);
+static void gimp_image_colormap_set_palette_entry (GimpImage *image,
+ gint index);
/* public functions */
@@ -173,11 +173,6 @@ gimp_image_set_colormap (GimpImage *image,
memcpy (private->colormap, colormap, n_colors * 3);
}
- else if (private->colormap)
- {
- gimp_image_colormap_dispose (image);
- gimp_image_colormap_free (image);
- }
private->n_colors = n_colors;
@@ -201,6 +196,31 @@ gimp_image_set_colormap (GimpImage *image,
}
void
+gimp_image_unset_colormap (GimpImage *image,
+ gboolean push_undo)
+{
+ GimpImagePrivate *private;
+
+ g_return_if_fail (GIMP_IS_IMAGE (image));
+
+ private = GIMP_IMAGE_GET_PRIVATE (image);
+
+ if (push_undo)
+ gimp_image_undo_push_image_colormap (image,
+ C_("undo-type", "Unset Colormap"));
+
+ if (private->colormap)
+ {
+ gimp_image_colormap_dispose (image);
+ gimp_image_colormap_free (image);
+ }
+
+ private->n_colors = 0;
+
+ gimp_image_colormap_changed (image, -1);
+}
+
+void
gimp_image_get_colormap_entry (GimpImage *image,
gint color_index,
GimpRGB *color)
@@ -286,7 +306,7 @@ gimp_image_add_colormap_entry (GimpImage *image,
/* private functions */
-void
+static void
gimp_image_colormap_set_palette_entry (GimpImage *image,
gint index)
{
diff --git a/app/core/gimpimage-colormap.h b/app/core/gimpimage-colormap.h
index 54be91e..5fc97be 100644
--- a/app/core/gimpimage-colormap.h
+++ b/app/core/gimpimage-colormap.h
@@ -34,6 +34,8 @@ void gimp_image_set_colormap (GimpImage *image,
const guchar *colormap,
gint n_colors,
gboolean push_undo);
+void gimp_image_unset_colormap (GimpImage *image,
+ gboolean push_undo);
void gimp_image_get_colormap_entry (GimpImage *image,
gint color_index,
diff --git a/app/core/gimpimage-convert.c b/app/core/gimpimage-convert.c
index 85b2790..b45cd21 100644
--- a/app/core/gimpimage-convert.c
+++ b/app/core/gimpimage-convert.c
@@ -1002,7 +1002,7 @@ gimp_image_convert (GimpImage *image,
case GIMP_RGB:
case GIMP_GRAY:
if (old_type == GIMP_INDEXED)
- gimp_image_set_colormap (image, NULL, 0, TRUE);
+ gimp_image_unset_colormap (image, TRUE);
break;
case GIMP_INDEXED:
diff --git a/app/core/gimpimageundo.c b/app/core/gimpimageundo.c
index f67a59f..99d1d40 100644
--- a/app/core/gimpimageundo.c
+++ b/app/core/gimpimageundo.c
@@ -415,9 +415,12 @@ gimp_image_undo_pop (GimpUndo *undo,
colormap = g_memdup (gimp_image_get_colormap (image),
GIMP_IMAGE_COLORMAP_SIZE);
- gimp_image_set_colormap (image,
- image_undo->colormap, image_undo->num_colors,
- FALSE);
+ if (image_undo->colormap)
+ gimp_image_set_colormap (image,
+ image_undo->colormap, image_undo->num_colors,
+ FALSE);
+ else
+ gimp_image_unset_colormap (image, FALSE);
if (image_undo->colormap)
g_free (image_undo->colormap);
diff --git a/app/widgets/gimppaletteview.c b/app/widgets/gimppaletteview.c
index a34dd50..959b867 100644
--- a/app/widgets/gimppaletteview.c
+++ b/app/widgets/gimppaletteview.c
@@ -433,7 +433,7 @@ gimp_palette_view_find_entry (GimpPaletteView *view,
palette = GIMP_PALETTE (GIMP_VIEW (view)->renderer->viewable);
renderer = GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (view)->renderer);
- if (! palette)
+ if (! palette || ! gimp_palette_get_n_colors (palette))
return NULL;
col = x / renderer->cell_width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]