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.
This commit is contained in:
Jehan 2021-01-30 00:20:34 +01:00
parent ee26a39049
commit 63d6d770c4
11 changed files with 116 additions and 52 deletions

View File

@ -549,11 +549,15 @@ compose_run (GimpProcedure *procedure,
}
else
{
gint source;
gint input[4] = { 0, };
gint nret;
gchar *parasite_data;
guint32 parasite_size;
gint source;
gint input[4] = { 0, };
gint nret;
nret = sscanf (gimp_parasite_data (parasite),
parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_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)
{

View File

@ -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 */

View File

@ -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, &parasite_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, &parasite_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, &parasite_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, &parasite_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;
}

View File

@ -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, &parasite_size);
profile_name = g_convert (parasite_data, parasite_size,
"UTF-8", "ISO-8859-1", NULL, NULL, NULL);
}
png_set_iCCP (pp,
info,

View File

@ -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, &parasite_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)))

View File

@ -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, &parasite_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;

View File

@ -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];

View File

@ -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, &parasite_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, &parasite_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, &parasite_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, &parasite_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, &parasite_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, &parasite_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);
}
}

View File

@ -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, &parasite_size);
fwrite (parasite_data, sizeof (guchar), parasite_size, fp);
fclose (fp);
gimp_parasite_free (parasite);

View File

@ -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, &parasite_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)

View File

@ -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, &parasite_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);