cgifsave: fix stack-use-after-scope (#2862)

By reusing `cgif->palette_rgb`, this ensures that `pLocalPalette`
doesn't become indeterminate when it reaches `cgif_addframe`.
This commit is contained in:
Kleis Auke Wolthuizen 2022-06-13 13:59:40 +02:00 committed by GitHub
parent 48d13f4828
commit ebfef68707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,7 +99,7 @@ typedef struct _VipsForeignSaveCgif {
int *palette; int *palette;
int n_colours; int n_colours;
/* The global palette as RGB (not RGBA). /* The palette as RGB (not RGBA).
*/ */
VipsPel palette_rgb[256 * 3]; VipsPel palette_rgb[256 * 3];
@ -576,12 +576,10 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
/* Attach a local palette, if we need one. /* Attach a local palette, if we need one.
*/ */
if( use_local ) { if( use_local ) {
VipsPel rgb[256 * 3];
vips_foreign_save_cgif_get_rgb_palette( cgif, vips_foreign_save_cgif_get_rgb_palette( cgif,
quantisation_result, rgb ); quantisation_result, cgif->palette_rgb );
frame_config.attrFlags |= CGIF_FRAME_ATTR_USE_LOCAL_TABLE; frame_config.attrFlags |= CGIF_FRAME_ATTR_USE_LOCAL_TABLE;
frame_config.pLocalPalette = rgb; frame_config.pLocalPalette = cgif->palette_rgb;
frame_config.numLocalPaletteEntries = n_colours; frame_config.numLocalPaletteEntries = n_colours;
} }