[FFmpeg-cvslog] SVQ3: do not modify const input buffer

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu May 5 17:53:25 CEST 2011


On Thu, May 05, 2011 at 04:06:15PM +0200, Baptiste Coudurier wrote:
> ffmpeg | branch: master | Baptiste Coudurier <baptiste.coudurier at gmail.com> | Thu May  5 15:17:51 2011 +0200| [2264c1108135380c49fdf0aef97520bf77a6ed37] | committer: Michael Niedermayer
> 
> SVQ3: do not modify const input buffer
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2264c1108135380c49fdf0aef97520bf77a6ed37
> ---
> 
>  libavcodec/svq3.c |   22 +++++++++++++++++++---
>  1 files changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
> index 9dff9e9..16f4834 100644
> --- a/libavcodec/svq3.c
> +++ b/libavcodec/svq3.c
> @@ -70,6 +70,8 @@ typedef struct {
>      int unknown_flag;
>      int next_slice_index;
>      uint32_t watermark_key;
> +    uint8_t *buf;
> +    int buf_size;
>  } SVQ3Context;
>  
>  #define FULLPEL_MODE  1
> @@ -927,12 +929,12 @@ static int svq3_decode_frame(AVCodecContext *avctx,
>                               void *data, int *data_size,
>                               AVPacket *avpkt)
>  {
> -    const uint8_t *buf = avpkt->data;
>      SVQ3Context *svq3 = avctx->priv_data;
>      H264Context *h = &svq3->h;
>      MpegEncContext *s = &h->s;
>      int buf_size = avpkt->size;
>      int m, mb_type, left;
> +    uint8_t *buf;
>  
>      /* special case for last picture */
>      if (buf_size == 0) {
> @@ -944,10 +946,21 @@ static int svq3_decode_frame(AVCodecContext *avctx,
>          return 0;
>      }
>  
> -    init_get_bits (&s->gb, buf, 8*buf_size);
> -
>      s->mb_x = s->mb_y = h->mb_xy = 0;
>  
> +    if (svq3->watermark_key) {
> +        svq3->buf = av_fast_realloc(svq3->buf, &svq3->buf_size,
> +                                    buf_size+FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!svq3->buf)
> +            return AVERROR(ENOMEM);

This will leak the old buffer on out of memory, and it does an
pointless memcpy in some cases.
av_fast_malloc should be the better choice here.


More information about the ffmpeg-cvslog mailing list