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

Conversation

kleisauke
Copy link
Member

liq_set_dithering_level could somehow free the palette, so
do the transparency check prior to that.

Note that GCC still prints this warning:

In function ‘vips_foreign_save_cgif_write_frame’,
    inlined from ‘vips_foreign_save_cgif_sink_disc’ at ../libvips/foreign/cgifsave.c:587:8:
../libvips/foreign/cgifsave.c:401:35: warning: ‘pal_local’ may be used uninitialized [-Wmaybe-uninitialized]
  401 |                 for( i = 0; i < lp->count; i++ ) {
      |                                 ~~^~~~~~~
../libvips/foreign/cgifsave.c: In function ‘vips_foreign_save_cgif_sink_disc’:
../libvips/foreign/cgifsave.c:261:54: note: ‘pal_local’ was declared here
  261 |         const VipsQuantisePalette *lp, *pal_global, *pal_local;
      |                                                      ^~~~~~~~~

(probably a false positive)

`liq_set_dithering_level` could somehow free the palette, so
do the transparency check prior to that.
@kleisauke kleisauke marked this pull request as draft June 10, 2022 10:32
@kleisauke
Copy link
Member Author

Marking as draft, since the palette is still fetched after vips__quantise_set_dithering_level.

trans_index = lp->count;

This seems to cause a new ASan failure:
https://github.com/libvips/libvips/runs/6828919349?check_suite_focus=true#step:18:327

@jcupitt
Copy link
Member

jcupitt commented Jun 10, 2022

I'm half-way through reworking cgifsave, I should have a PR with a rewritten (and easier to maintain) version later today.

@jcupitt
Copy link
Member

jcupitt commented Jun 10, 2022

Should be fixed with #2853

@jcupitt jcupitt closed this Jun 10, 2022
@kleisauke kleisauke deleted the cgifsave-fix-asan branch June 11, 2022 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants