[gimp] plug-ins: replace gimp_parasite_data*() with gimp_parasite_get_data().
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: replace gimp_parasite_data*() with gimp_parasite_get_data().
- Date: Sat, 30 Jan 2021 07:40:47 +0000 (UTC)
commit 63d6d770c4125fffe93865165d55e3496a35e6c7
Author: Jehan <jehan girinstud io>
Date: Sat Jan 30 00:20:34 2021 +0100
plug-ins: replace gimp_parasite_data*() with gimp_parasite_get_data().
Similarly to the previous commit, it is not only about using the new
API. I also make sure we do not assume that parasite data is
nul-terminated. In many places, we were just assuming so because these
were supposed to be parasite our code set. Yet these are data input
contained in files which can be wrong for any reason (corrupted file,
bugs, other scripts/plug-ins editing these parasites…). So instead of
assuming string parasites are always correctly formatted, I make sure
they are nul-terminated by passing them through g_strndup() when
necessary.
plug-ins/common/compose.c | 15 ++++++++-----
plug-ins/common/file-dicom.c | 6 ++++--
plug-ins/common/file-gih.c | 43 +++++++++++++++++++++++++++++--------
plug-ins/common/file-png.c | 11 +++++++---
plug-ins/common/file-xbm.c | 10 +++++++--
plug-ins/common/file-xmc.c | 12 +++++++++--
plug-ins/file-jpeg/jpeg-settings.c | 15 ++++++-------
plug-ins/file-tiff/file-tiff-save.c | 33 +++++++++++++++++-----------
plug-ins/gfig/gfig.c | 8 +++----
plug-ins/ifs-compose/ifs-compose.c | 9 ++++++--
plug-ins/print/print-utils.c | 8 ++++---
11 files changed, 117 insertions(+), 53 deletions(-)
---
diff --git a/plug-ins/common/compose.c b/plug-ins/common/compose.c
index 356d197833..fc0c421a63 100644
--- a/plug-ins/common/compose.c
+++ b/plug-ins/common/compose.c
@@ -549,11 +549,15 @@ compose_run (GimpProcedure *procedure,
}
else
{
- gint source;
- gint input[4] = { 0, };
- gint nret;
-
- nret = sscanf (gimp_parasite_data (parasite),
+ gchar *parasite_data;
+ guint32 parasite_size;
+ gint source;
+ gint input[4] = { 0, };
+ gint nret;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+ nret = sscanf (parasite_data,
"source=%d type=%31s %d %d %d %d",
&source,
composevals.compose_type,
@@ -563,6 +567,7 @@ compose_run (GimpProcedure *procedure,
input + 3);
gimp_parasite_free (parasite);
+ g_free (parasite_data);
if (nret < 5)
{
diff --git a/plug-ins/common/file-dicom.c b/plug-ins/common/file-dicom.c
index 4de4ce13a1..f2bbd3852e 100644
--- a/plug-ins/common/file-dicom.c
+++ b/plug-ins/common/file-dicom.c
@@ -1147,8 +1147,10 @@ dicom_get_elements_list (GimpImage *image)
*/
if (group_word > 0 && element_word > 0)
{
- const guint8 *val = gimp_parasite_data (parasite);
- const guint len = gimp_parasite_data_size (parasite);
+ const guint8 *val;
+ guint32 len;
+
+ val = (const guint8 *) gimp_parasite_get_data (parasite, &len);
/* and add the dicom element, asking to have
it's value copied for later garbage collection */
diff --git a/plug-ins/common/file-gih.c b/plug-ins/common/file-gih.c
index b9613af026..a21a49aece 100644
--- a/plug-ins/common/file-gih.c
+++ b/plug-ins/common/file-gih.c
@@ -307,10 +307,13 @@ gih_save (GimpProcedure *procedure,
"gimp-brush-pipe-name");
if (parasite)
{
- g_strlcpy (info.description,
- gimp_parasite_data (parasite),
- MIN (sizeof (info.description),
- gimp_parasite_data_size (parasite)));
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+
+ g_strlcpy (info.description, parasite_data,
+ MIN (sizeof (info.description), parasite_size));
gimp_parasite_free (parasite);
}
@@ -331,8 +334,16 @@ gih_save (GimpProcedure *procedure,
"gimp-brush-pipe-spacing");
if (parasite)
{
- info.spacing = atoi (gimp_parasite_data (parasite));
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+
+ info.spacing = atoi (parasite_data);
+
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
break;
@@ -356,9 +367,16 @@ gih_save (GimpProcedure *procedure,
"gimp-brush-pipe-parameters");
if (parasite)
{
- gimp_pixpipe_params_parse (gimp_parasite_data (parasite),
- &gihparams);
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+
+ gimp_pixpipe_params_parse (parasite_data, &gihparams);
+
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
/* Force default rank to same as number of cells if there is
@@ -410,9 +428,16 @@ gih_save (GimpProcedure *procedure,
"gimp-brush-pipe-parameters");
if (parasite)
{
- gimp_pixpipe_params_parse (gimp_parasite_data (parasite),
- &gihparams);
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+
+ gimp_pixpipe_params_parse (parasite_data, &gihparams);
+
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
break;
}
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index dc517eca1b..196bdeb5ed 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1771,9 +1771,14 @@ save_image (GFile *file,
parasite = gimp_image_get_parasite (orig_image,
"icc-profile-name");
if (parasite)
- profile_name = g_convert (gimp_parasite_data (parasite),
- gimp_parasite_data_size (parasite),
- "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ {
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ profile_name = g_convert (parasite_data, parasite_size,
+ "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ }
png_set_iCCP (pp,
info,
diff --git a/plug-ins/common/file-xbm.c b/plug-ins/common/file-xbm.c
index ab1a673d23..c3cd26fc61 100644
--- a/plug-ins/common/file-xbm.c
+++ b/plug-ins/common/file-xbm.c
@@ -395,9 +395,14 @@ xbm_save (GimpProcedure *procedure,
if (parasite)
{
- gint x, y;
+ gchar *parasite_data;
+ guint32 parasite_size;
+ gint x, y;
- if (sscanf (gimp_parasite_data (parasite), "%i %i", &x, &y) == 2)
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+
+ if (sscanf (parasite_data, "%i %i", &x, &y) == 2)
{
g_object_set (config,
"use-hot-spot", TRUE,
@@ -407,6 +412,7 @@ xbm_save (GimpProcedure *procedure,
}
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
if (! save_dialog (drawables[0], procedure, G_OBJECT (config)))
diff --git a/plug-ins/common/file-xmc.c b/plug-ins/common/file-xmc.c
index 2804dd1454..5810b876a1 100644
--- a/plug-ins/common/file-xmc.c
+++ b/plug-ins/common/file-xmc.c
@@ -1901,15 +1901,23 @@ get_hotspot_from_parasite (GimpImage *image,
if (parasite)
{
- gint x, y;
+ gchar *parasite_data;
+ guint32 parasite_size;
+ gint x, y;
- if (sscanf (gimp_parasite_data (parasite), "%i %i", &x, &y) == 2)
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+
+ if (sscanf (parasite_data, "%i %i", &x, &y) == 2)
{
*hot_spot_x = x;
*hot_spot_y = y;
+ g_free (parasite_data);
+
return TRUE;
}
+ g_free (parasite_data);
}
return FALSE;
diff --git a/plug-ins/file-jpeg/jpeg-settings.c b/plug-ins/file-jpeg/jpeg-settings.c
index dbd1264db8..3bdc086cc9 100644
--- a/plug-ins/file-jpeg/jpeg-settings.c
+++ b/plug-ins/file-jpeg/jpeg-settings.c
@@ -172,7 +172,7 @@ jpeg_restore_original_settings (GimpImage *image,
{
GimpParasite *parasite;
const guchar *src;
- glong src_size;
+ guint32 src_size;
gint color_space;
gint q;
gint num_components;
@@ -187,8 +187,7 @@ jpeg_restore_original_settings (GimpImage *image,
parasite = gimp_image_get_parasite (image, "jpeg-settings");
if (parasite)
{
- src = gimp_parasite_data (parasite);
- src_size = gimp_parasite_data_size (parasite);
+ src = gimp_parasite_get_data (parasite, &src_size);
if (src_size >= 4)
{
color_space = *src++;
@@ -273,7 +272,7 @@ jpeg_restore_original_tables (GimpImage *image,
{
GimpParasite *parasite;
const guchar *src;
- glong src_size;
+ guint32 src_size;
gint num_components;
gint num_tables;
guint **quant_tables;
@@ -283,10 +282,9 @@ jpeg_restore_original_tables (GimpImage *image,
parasite = gimp_image_get_parasite (image, "jpeg-settings");
if (parasite)
{
- src_size = gimp_parasite_data_size (parasite);
+ src = gimp_parasite_get_data (parasite, &src_size);
if (src_size >= 4)
{
- src = gimp_parasite_data (parasite);
num_components = src[2];
num_tables = src[3];
@@ -332,7 +330,7 @@ jpeg_swap_original_settings (GimpImage *image)
{
GimpParasite *parasite;
const guchar *src;
- glong src_size;
+ guint32 src_size;
gint num_components;
gint num_tables;
guchar *new_data;
@@ -344,10 +342,9 @@ jpeg_swap_original_settings (GimpImage *image)
parasite = gimp_image_get_parasite (image, "jpeg-settings");
if (parasite)
{
- src_size = gimp_parasite_data_size (parasite);
+ src = gimp_parasite_get_data (parasite, &src_size);
if (src_size >= 4)
{
- src = gimp_parasite_data (parasite);
num_components = src[2];
num_tables = src[3];
diff --git a/plug-ins/file-tiff/file-tiff-save.c b/plug-ins/file-tiff/file-tiff-save.c
index 067c9aa44f..56d41ae93e 100644
--- a/plug-ins/file-tiff/file-tiff-save.c
+++ b/plug-ins/file-tiff/file-tiff-save.c
@@ -822,65 +822,74 @@ save_layer (TIFF *tif,
if (config_save_geotiff_tags)
{
GimpParasite *parasite = NULL;
+ gchar *parasite_data;
+ guint32 parasite_size;
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_ModelPixelScale");
-
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
TIFFSetField (tif,
GEOTIFF_MODELPIXELSCALE,
- (gimp_parasite_data_size (parasite) / TIFFDataWidth (TIFF_DOUBLE)),
- gimp_parasite_data (parasite));
+ (parasite_size / TIFFDataWidth (TIFF_DOUBLE)),
+ parasite_data);
gimp_parasite_free (parasite);
}
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_ModelTiePoint");
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
TIFFSetField (tif,
GEOTIFF_MODELTIEPOINT,
- (gimp_parasite_data_size (parasite) / TIFFDataWidth (TIFF_DOUBLE)),
- gimp_parasite_data (parasite));
+ (parasite_size / TIFFDataWidth (TIFF_DOUBLE)),
+ parasite_data);
gimp_parasite_free (parasite);
}
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_ModelTransformation");
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
TIFFSetField (tif,
GEOTIFF_MODELTRANSFORMATION,
- (gimp_parasite_data_size (parasite) / TIFFDataWidth (TIFF_DOUBLE)),
- gimp_parasite_data (parasite));
+ (parasite_size / TIFFDataWidth (TIFF_DOUBLE)),
+ parasite_data);
gimp_parasite_free (parasite);
}
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_KeyDirectory");
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
TIFFSetField (tif,
GEOTIFF_KEYDIRECTORY,
- (gimp_parasite_data_size (parasite) / TIFFDataWidth (TIFF_SHORT)),
- gimp_parasite_data (parasite));
+ (parasite_size / TIFFDataWidth (TIFF_SHORT)),
+ parasite_data);
gimp_parasite_free (parasite);
}
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_DoubleParams");
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
TIFFSetField (tif,
GEOTIFF_DOUBLEPARAMS,
- (gimp_parasite_data_size (parasite) / TIFFDataWidth (TIFF_DOUBLE)),
- gimp_parasite_data (parasite));
+ (parasite_size / TIFFDataWidth (TIFF_DOUBLE)),
+ parasite_data);
gimp_parasite_free (parasite);
}
parasite = gimp_image_get_parasite (image,"Gimp_GeoTIFF_Asciiparams");
if (parasite)
{
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
TIFFSetField (tif,
GEOTIFF_ASCIIPARAMS,
- gimp_parasite_data (parasite));
+ parasite_data);
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
}
diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c
index bfd8d8efc1..c0cd2c3c9a 100644
--- a/plug-ins/gfig/gfig.c
+++ b/plug-ins/gfig/gfig.c
@@ -774,6 +774,8 @@ gfig_load_from_parasite (void)
gchar *fname;
FILE *fp;
GimpParasite *parasite;
+ const gchar *parasite_data;
+ guint32 parasite_size;
GFigObj *gfig;
parasite = gimp_item_get_parasite (GIMP_ITEM (gfig_context->drawable),
@@ -793,10 +795,8 @@ gfig_load_from_parasite (void)
return NULL;
}
- fwrite (gimp_parasite_data (parasite),
- sizeof (guchar),
- gimp_parasite_data_size (parasite),
- fp);
+ parasite_data = gimp_parasite_get_data (parasite, ¶site_size);
+ fwrite (parasite_data, sizeof (guchar), parasite_size, fp);
fclose (fp);
gimp_parasite_free (parasite);
diff --git a/plug-ins/ifs-compose/ifs-compose.c b/plug-ins/ifs-compose/ifs-compose.c
index 7a299a6f20..6d203a52b8 100644
--- a/plug-ins/ifs-compose/ifs-compose.c
+++ b/plug-ins/ifs-compose/ifs-compose.c
@@ -413,9 +413,14 @@ ifs_run (GimpProcedure *procedure,
PLUG_IN_PARASITE);
if (parasite)
{
- found_parasite = ifsvals_parse_string (gimp_parasite_data (parasite),
- &ifsvals, &elements);
+ gchar *parasite_data;
+ guint32 parasite_size;
+
+ parasite_data = (gchar *) gimp_parasite_get_data (parasite, ¶site_size);
+ parasite_data = g_strndup (parasite_data, parasite_size);
+ found_parasite = ifsvals_parse_string (parasite_data, &ifsvals, &elements);
gimp_parasite_free (parasite);
+ g_free (parasite_data);
}
if (! found_parasite)
diff --git a/plug-ins/print/print-utils.c b/plug-ins/print/print-utils.c
index 0e921a2296..a264d22463 100644
--- a/plug-ins/print/print-utils.c
+++ b/plug-ins/print/print-utils.c
@@ -52,6 +52,9 @@ print_utils_key_file_load_from_parasite (GimpImage *image,
GimpParasite *parasite;
GKeyFile *key_file;
GError *error = NULL;
+ const gchar *parasite_data;
+ guint32 parasite_size;
+
g_return_val_if_fail (parasite_name != NULL, NULL);
@@ -62,9 +65,8 @@ print_utils_key_file_load_from_parasite (GimpImage *image,
key_file = g_key_file_new ();
- if (! g_key_file_load_from_data (key_file,
- gimp_parasite_data (parasite),
- gimp_parasite_data_size (parasite),
+ parasite_data = gimp_parasite_get_data (parasite, ¶site_size);
+ if (! g_key_file_load_from_data (key_file, parasite_data, parasite_size,
G_KEY_FILE_NONE, &error))
{
g_key_file_free (key_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]