-const char deanimate_rcs[] = "$Id: deanimate.c,v 1.22 2011/12/31 14:47:44 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/deanimate.c,v $
* - Deanimation of GIF images
*
* Copyright : Written by and Copyright (C) 2001 - 2004, 2006 by the
- * SourceForge Privoxy team. http://www.privoxy.org/
+ * 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, <ksm+cpan@universal.dca.net>
*
#include <string.h>
#include <fcntl.h>
-#include "errlog.h"
#include "project.h"
+#include "errlog.h"
#include "deanimate.h"
#include "miscutil.h"
-const char deanimate_h_rcs[] = DEANIMATE_H_VERSION;
-
/*********************************************************************
*
* Function : buf_free
*********************************************************************/
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
* an (optional) image block and an arbitrary number
* of image extension blocks, produce an output GIF with
* only one image block that contains the last image
- * (extenstion) block of the original.
- * Also strip Comments, Application extenstions, etc.
+ * (extension) block of the original.
+ * Also strip Comments, Application extensions, etc.
*
* Parameters :
* 1 : src = Pointer to the source binbuffer
{
return 1;
}
+ if (src->size <= 10)
+ {
+ return 1;
+ }
c = buf_getbyte(src, 10);
/*
* Reserve a buffer for the current image block
*/
- if (NULL == (image = (struct binbuffer *)zalloc(sizeof(*image))))
- {
- return 1;
- }
+ image = zalloc_or_die(sizeof(*image));
/*
* Parse the GIF block by block and copy the relevant
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;
/*