[FFmpeg-devel] [PATCH] animated gif decoding

Michael Niedermayer michaelni
Wed Jun 3 18:16:13 CEST 2009


On Sat, May 30, 2009 at 10:20:46PM -0700, Baptiste Coudurier wrote:
> Michael Niedermayer wrote:
> > 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
> > 
> 
> Adressed. Updated patch attached.
> 
> -- 
> Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
> Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer                                  http://www.ffmpeg.org

>  gifdec.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++----------------
>  1 file changed, 49 insertions(+), 16 deletions(-)
> d5e41ebf0567c1d983688426983971e9f2ec1982  animated_gif2.patch

looks ok

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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- 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/20090603/23de3a86/attachment.pgp>



More information about the ffmpeg-devel mailing list