[FFmpeg-devel] [PATCH] Deprecate av_fifo_realloc() in favour of a safer av_fifo_realloc2()

Stefano Sabatini stefano.sabatini-lala
Mon Aug 11 11:14:18 CEST 2008


On date Thursday 2008-08-07 12:38:00 +0200, Stefano Sabatini encoded:
> On date Thursday 2008-08-07 00:58:09 +0200, Michael Niedermayer encoded:
> > On Wed, Aug 06, 2008 at 12:01:32AM +0200, Stefano Sabatini wrote:
> > > Hi all,
> > > 
> > > in the case the av_malloc() performed in av_fifo_init() inside
> > > av_fifo_relloc() fails, and if the buffer in the fifo to realloc
> > > contains something, the av_fifo_realloc() issues a crash.
> > > 
> > > Test application which reproduces the issue and my solution attached.
> > > 
> > > Yes the libavutil minor version bump is missing.
> > [...]
> > > Index: libavutil/fifo.h
> > > ===================================================================
> > > --- libavutil/fifo.h	(revision 14627)
> > > +++ libavutil/fifo.h	(working copy)
> > > @@ -97,10 +97,19 @@
> > >   * Resizes an AVFifoBuffer.
> > >   * @param *f AVFifoBuffer to resize
> > >   * @param size new AVFifoBuffer size in bytes
> > > + * @see av_fifo_realloc2()
> > >   */
> > > -void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
> > > +attribute_deprecated void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
> > >  
> > 
> > should be under #if VERSION < ...
> 
> Yes, if this is OK I'm also going to remove the unnecessary doxy in
> fifo.c
> 
> Regards.
> -- 
> FFmpeg = Foolish and Freak Monstrous Portentous Exxagerate Gadget

> Index: libavutil/avutil.h
> ===================================================================
> --- libavutil/avutil.h	(revision 14660)
> +++ libavutil/avutil.h	(working copy)
> @@ -35,7 +35,7 @@
>  #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
>  
>  #define LIBAVUTIL_VERSION_MAJOR 49
> -#define LIBAVUTIL_VERSION_MINOR  7
> +#define LIBAVUTIL_VERSION_MINOR  8
>  #define LIBAVUTIL_VERSION_MICRO  0
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> Index: libavutil/fifo.h
> ===================================================================
> --- libavutil/fifo.h	(revision 14660)
> +++ libavutil/fifo.h	(working copy)
> @@ -93,14 +93,25 @@
>   */
>  int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
>  
> +#if LIBAVUTIL_VERSION_MAJOR < 50
>  /**
>   * Resizes an AVFifoBuffer.
>   * @param *f AVFifoBuffer to resize
>   * @param size new AVFifoBuffer size in bytes
> + * @see av_fifo_realloc2()
>   */
> -void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
> +attribute_deprecated void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
> +#endif
>  
>  /**
> + * Resizes an AVFifoBuffer.
> + * @param *f AVFifoBuffer to resize
> + * @param size new AVFifoBuffer size in bytes
> + * @return <0 for failure >=0 otherwise
> + */
> +int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
> +
> +/**
>   * Reads and discards the specified amount of data from an AVFifoBuffer.
>   * @param *f AVFifoBuffer to read from
>   * @param size amount of data to read in bytes
> Index: libavutil/fifo.c
> ===================================================================
> --- libavutil/fifo.c	(revision 14660)
> +++ libavutil/fifo.c	(working copy)
> @@ -51,22 +51,30 @@
>      return av_fifo_generic_read(f, buf_size, NULL, buf);
>  }
>  
> +#if LIBAVUTIL_VERSION_MAJOR < 50
>  /**
>   * Resizes a FIFO.
>   */
>  void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
> +    av_fifo_realloc2(f, new_size);
> +}
> +#endif
> +
> +int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
>      unsigned int old_size= f->end - f->buffer;
>  
>      if(old_size <= new_size){
>          int len= av_fifo_size(f);
>          AVFifoBuffer f2;
>  
> -        av_fifo_init(&f2, new_size);
> +        if (av_fifo_init(&f2, new_size) < 0)
> +            return -1;
>          av_fifo_read(f, f2.buffer, len);
>          f2.wptr += len;
>          av_free(f->buffer);
>          *f= f2;
>      }
> +    return 0;
>  }
>  
>  void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)

Ping?
-- 
FFmpeg = Fostering and Friendly Multimedia Porno Enigmatic Gorilla




More information about the ffmpeg-devel mailing list