X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=deanimate.c;h=a6759da42644b18e6dd6bfcef323809dd73f8150;hp=bba74d49bf233f8b86c6c850ec7f6b873952fc59;hb=7f54fd0d1028f93f6ad9afe5e2d0a75b2263d06a;hpb=ad73cb711a97c6a600f4541bbad239781208bd60 diff --git a/deanimate.c b/deanimate.c index bba74d49..a6759da4 100644 --- a/deanimate.c +++ b/deanimate.c @@ -10,7 +10,7 @@ * Privoxy team. https://www.privoxy.org/ * * Based on the GIF file format specification (see - * http://tronche.com/computer-graphics/gif/gif89a.html) + * https://tronche.com/computer-graphics/gif/gif89a.html) * and ideas from the Image::DeAnim Perl module by * Ken MacFarlane, * @@ -131,6 +131,14 @@ static int buf_extend(struct binbuffer *buf, size_t length) *********************************************************************/ static int buf_copy(struct binbuffer *src, struct binbuffer *dst, size_t length) { + /* + * Sanity check: Make sure the source buffer contains + * data and there's work to be done. + */ + if (src->buffer == NULL || src->size == 0 || length == 0) + { + return 1; + } /* * Sanity check: Can't copy more data than we have @@ -325,6 +333,10 @@ int gif_deanimate(struct binbuffer *src, struct binbuffer *dst, int get_first_im { return 1; } + if (src->size <= 10) + { + return 1; + } c = buf_getbyte(src, 10); @@ -375,9 +387,11 @@ int gif_deanimate(struct binbuffer *src, struct binbuffer *dst, int get_first_im switch(buf_getbyte(src, 0)) { /* - * End-of-GIF Marker: Append current image and return + * End-of-GIF Marker: Append current image if we got + * one and return. */ case 0x3b: + if (image->size == 0) goto failed; goto write; /*