[FFmpeg-devel] [PATCH 03/17] avcodec/movtextdec: add some memory checks

Nicolas George george at nsup.org
Sun Sep 21 11:09:23 CEST 2014


Le jour de la Raison, an CCXXII, Clément Bœsch a écrit :
> ---
>  libavcodec/movtextdec.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
> index 05ff53a..deb7553 100644
> --- a/libavcodec/movtextdec.c
> +++ b/libavcodec/movtextdec.c
> @@ -60,7 +60,7 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
>                              void *data, int *got_sub_ptr, AVPacket *avpkt)
>  {
>      AVSubtitle *sub = data;
> -    int ts_start, ts_end;
> +    int ret, ts_start, ts_end;
>      AVBPrint buf;
>      const char *ptr = avpkt->data;
>      const char *end;
> @@ -98,11 +98,13 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
>      text_to_ass(&buf, ptr, end);
>  
>      if (!av_bprint_is_complete(&buf))
> -        return AVERROR(ENOMEM);
> -
> -    ff_ass_add_rect(sub, buf.str, ts_start, ts_end-ts_start, 0);
> -    *got_sub_ptr = sub->num_rects > 0;

> +        ret = AVERROR(ENOMEM);
> +    else
> +        ret = ff_ass_add_rect(sub, buf.str, ts_start, ts_end-ts_start, 0);
>      av_bprint_finalize(&buf, NULL);
> +    if (ret < 0)
> +        return ret;

Looks like this pattern is appearing a lot in this series: maybe
ff_ass_add_rect_from_bprint() to do that in a single step?

Looks correct anyway.

> +    *got_sub_ptr = sub->num_rects > 0;
>      return avpkt->size;
>  }
>  

Regards,

-- 
  Nicolas George


More information about the ffmpeg-devel mailing list