mirror of https://github.com/GNOME/gimp.git
Bug 555777 – Export to MNG animation fails
'mng_putchunk_plte' and 'mng_putchunk_trns' both copy the array passed in as if it was full size even when it is only partly used. This commit wraps their calls passing the arrays dimensioned correctly. In function 'respin_cmap', when 'find_unused_ia_colour' returns an index suitable for transparency the number of colors in the colormap, the following loop used to access three values beyond the end of the array 'before'. Finally fix a typo in a call to mng_putchunk_text().
This commit is contained in:
parent
580b932c8c
commit
e0f21468d4
|
@ -463,7 +463,7 @@ respin_cmap (png_structp png_ptr,
|
|||
|
||||
if (transparent != -1)
|
||||
{
|
||||
png_color palette[256];
|
||||
png_color palette[256] = { {0, 0, 0} };
|
||||
gint i;
|
||||
|
||||
png_set_tRNS (png_ptr, png_info_ptr, (png_bytep) trans, 1, NULL);
|
||||
|
@ -481,7 +481,7 @@ respin_cmap (png_structp png_ptr,
|
|||
* unchanged, and finally from index transparent to index 0.
|
||||
*/
|
||||
|
||||
for (i = 0; i < colors; i++)
|
||||
for (i = 1; i < colors; i++)
|
||||
{
|
||||
palette[i].red = before[3 * remap[i]];
|
||||
palette[i].green = before[3 * remap[i] + 1];
|
||||
|
@ -504,6 +504,41 @@ respin_cmap (png_structp png_ptr,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static mng_retcode
|
||||
mng_putchunk_plte_wrapper (mng_handle handle,
|
||||
gint numcolors,
|
||||
const guchar *colormap)
|
||||
{
|
||||
mng_palette8 palette;
|
||||
|
||||
memset (palette, 0, sizeof palette);
|
||||
if (0 < numcolors)
|
||||
memcpy (palette, colormap, numcolors * sizeof palette[0]);
|
||||
|
||||
return mng_putchunk_plte (handle, numcolors, palette);
|
||||
}
|
||||
|
||||
static mng_retcode
|
||||
mng_putchunk_trns_wrapper (mng_handle handle,
|
||||
gint n_alphas,
|
||||
const guchar *buffer)
|
||||
{
|
||||
const mng_bool mng_global = TRUE;
|
||||
const mng_bool mng_empty = TRUE;
|
||||
mng_uint8arr alphas;
|
||||
|
||||
memset (alphas, 0, sizeof alphas);
|
||||
if (buffer && 0 < n_alphas)
|
||||
memcpy (alphas, buffer, n_alphas * sizeof alphas[0]);
|
||||
|
||||
return mng_putchunk_trns (handle,
|
||||
! mng_empty,
|
||||
! mng_global,
|
||||
MNG_COLORTYPE_INDEXED,
|
||||
n_alphas,
|
||||
alphas,
|
||||
0, 0, 0, 0, 0, alphas);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mng_save_image (const gchar *filename,
|
||||
|
@ -637,7 +672,7 @@ mng_save_image (const gchar *filename,
|
|||
|
||||
if (mng_putchunk_text (handle,
|
||||
strlen (MNG_TEXT_TITLE), MNG_TEXT_TITLE,
|
||||
22, "Created using GIMP") != MNG_NOERROR)
|
||||
18, "Created using GIMP") != MNG_NOERROR)
|
||||
{
|
||||
g_warning ("Unable to mng_putchunk_text() in mng_save_image()");
|
||||
goto err3;
|
||||
|
@ -731,8 +766,8 @@ mng_save_image (const gchar *filename,
|
|||
palette = gimp_image_get_colormap (image_id, &numcolors);
|
||||
|
||||
if ((numcolors != 0) &&
|
||||
(mng_putchunk_plte (handle, numcolors,
|
||||
(mng_palette8e *) palette) != MNG_NOERROR))
|
||||
(mng_putchunk_plte_wrapper (handle, numcolors,
|
||||
palette) != MNG_NOERROR))
|
||||
{
|
||||
g_warning ("Unable to mng_putchunk_plte() in mng_save_image()");
|
||||
goto err3;
|
||||
|
@ -1168,11 +1203,10 @@ mng_save_image (const gchar *filename,
|
|||
/* If this frame's palette is the same as the global palette,
|
||||
* write a 0-color palette chunk.
|
||||
*/
|
||||
if (mng_putchunk_plte (handle,
|
||||
(layer_has_unique_palette ?
|
||||
(chunksize / 3) : 0),
|
||||
(mng_palette8e *) chunkbuffer) !=
|
||||
MNG_NOERROR)
|
||||
if (mng_putchunk_plte_wrapper (handle,
|
||||
(layer_has_unique_palette ?
|
||||
(chunksize / 3) : 0),
|
||||
chunkbuffer) != MNG_NOERROR)
|
||||
{
|
||||
g_warning ("Unable to mng_putchunk_plte() "
|
||||
"in mng_save_image()");
|
||||
|
@ -1181,10 +1215,9 @@ mng_save_image (const gchar *filename,
|
|||
}
|
||||
else if (strncmp (chunkname, "tRNS", 4) == 0)
|
||||
{
|
||||
if (mng_putchunk_trns (handle, 0, 0, 3, chunksize,
|
||||
(mng_uint8 *) chunkbuffer,
|
||||
0, 0, 0, 0, 0,
|
||||
(mng_uint8 *) chunkbuffer) != MNG_NOERROR)
|
||||
if (mng_putchunk_trns_wrapper (handle,
|
||||
chunksize,
|
||||
chunkbuffer) != MNG_NOERROR)
|
||||
{
|
||||
g_warning ("Unable to mng_putchunk_trns() "
|
||||
"in mng_save_image()");
|
||||
|
|
Loading…
Reference in New Issue