[FFmpeg-devel] [PATCH] animated gif decoding

Michael Niedermayer michaelni
Sun May 31 00:36:42 CEST 2009


On Fri, May 29, 2009 at 10:29:33PM -0700, Baptiste Coudurier wrote:
> Hi guys,
> 
> $subject, it uses CODEC_CAP_DELAY for this.
> Comments and suggestions welcome.
> 
> -- 
> Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
> Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer                                  http://www.ffmpeg.org

>  gifdec.c |   64 +++++++++++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 46 insertions(+), 18 deletions(-)
> 62382a9c697506f29c2d2ba3781e8e3856ef8c06  animated_gif.patch
> Index: libavcodec/gifdec.c
> ===================================================================
> --- libavcodec/gifdec.c	(revision 18990)
> +++ libavcodec/gifdec.c	(working copy)
> @@ -41,6 +41,9 @@
>      int color_resolution;
>      uint32_t *image_palette;
>  
> +    uint8_t *buf; ///< gif image copied

gif image copY ?


> +    int buf_size;
> +
>      /* after the frame is displayed, the disposal method is used */
>      int gce_disposal;
>      /* delay during which the frame is shown */
> @@ -152,7 +155,7 @@
>      /* read the garbage data until end marker is found */
>      ff_lzw_decode_tail(s->lzw);
>      s->bytestream = ff_lzw_cur_ptr(s->lzw);
> -    return 0;
> +    return 1;
>  }
>  
>  static int gif_read_extension(GifState *s)
> @@ -202,19 +205,12 @@
>  
>  static int gif_read_header1(GifState *s)
>  {
> -    uint8_t sig[6];
>      int v, n;
>      int has_global_palette;
>  
> -    if (s->bytestream_end < s->bytestream + 13)
> +    if (s->bytestream_end < s->bytestream + 7)
>          return -1;
>  
> -    /* read gif signature */
> -    bytestream_get_buffer(&s->bytestream, sig, 6);
> -    if (memcmp(sig, gif87a_sig, 6) != 0 &&
> -        memcmp(sig, gif89a_sig, 6) != 0)
> -        return -1;
> -
>      /* read screen header */
>      s->transparent_color_index = -1;
>      s->screen_width = bytestream_get_le16(&s->bytestream);

> @@ -259,8 +255,8 @@
>              if (gif_read_extension(s) < 0)
>                  return -1;
>              break;
> -        case ';':
> -            /* end of image */
> +        case ';': /* end of image */

cosmetic


> +            return 0;
>          default:
>              /* error or erroneous EOF */
>              return -1;

> @@ -290,11 +286,32 @@
>      AVFrame *picture = data;
>      int ret;
>  
> -    s->bytestream = buf;
> -    s->bytestream_end = buf + buf_size;
> -    if (gif_read_header1(s) < 0)
> +    *data_size = 0;
> +
> +    if (buf) {
> +        if ((int64_t)s->buf_size+buf_size >= UINT_MAX)
> +            return -1;

> +        s->buf = av_realloc(s->buf, s->buf_size+buf_size);
> +        if (!s->buf)
> +            return -1;

memleak


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090531/d2de6a11/attachment.pgp>



More information about the ffmpeg-devel mailing list