Skip to content

cgifsave: fix heap-use-after-free #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libvips/foreign/cgifsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
if( cur[3] >= 128 )
cur[3] = 255;
else {
/* Helps the quanizer generate a better palette.
/* Helps the quantizer generate a better palette.
*/
cur[0] = 0;
cur[1] = 0;
Expand Down Expand Up @@ -366,7 +366,7 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )

/* Also drop saved local result as it's usage
* doesn't make sense now and it's better to
* use a new local result if neeeded
* use a new local result if needed
*/
VIPS_FREEF( vips__quantise_result_destroy,
cgif->local_quantisation_result );
Expand Down Expand Up @@ -407,6 +407,10 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
}
}

/* If there's a transparent pixel, it's always first.
*/
cgif->has_transparency = lp->entries[0].a == 0;

/* Dither frame.
*/
vips__quantise_set_dithering_level( quantisation_result, cgif->dither );
Expand All @@ -416,10 +420,6 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif )
return( -1 );
}

/* If there's a transparent pixel, it's always first.
*/
cgif->has_transparency = lp->entries[0].a == 0;

/* Set up cgif on first use, so we can set the first cmap as the global
* one.
*
Expand Down