On Mon, Sep 09, 2013 at 11:41:00AM +0200, Alexandra Khirnova wrote:
> ---
>  libavformat/asfenc.c      |   10 +++++++---
>  libavformat/gxfenc.c      |   20 ++++++++++++--------
>  libavformat/matroskadec.c |   11 ++++++-----
>  libavformat/matroskaenc.c |   18 ++++++++++++------
>  libavformat/mov.c         |   40 ++++++++++++++++++++++------------------
>  libavformat/mpegts.c      |    6 +++---
>  libavformat/mxfdec.c      |   24 ++++++++++++++----------
>  libavformat/oggdec.c      |   15 ++++++---------
>  libavformat/utils.c       |   18 ++++++++----------
>  9 files changed, 90 insertions(+), 72 deletions(-)

... getting there ...

> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -878,15 +878,16 @@ static int ebml_parse_elem(MatroskaDemuxContext 
> *matroska,
>      data = (char *)data + syntax->data_offset;
>      if (syntax->list_elem_size) {
>          EbmlList *list = data;
> -        newelem = av_realloc(list->elem, 
> (list->nb_elem+1)*syntax->list_elem_size);
> -        if (!newelem)
> -            return AVERROR(ENOMEM);
> -        list->elem = newelem;
> +        if ((res = av_reallocp_array(&list->elem,
> +                                     list->nb_elem + 1,
> +                                     syntax->list_elem_size)) < 0) {

I wonder why this does not use plain sizeof.

> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -100,16 +100,13 @@ static int ogg_restore(AVFormatContext *s, int discard)
>          avio_seek(bc, ost->pos, SEEK_SET);
>          ogg->curidx   = ost->curidx;
>          ogg->nstreams = ost->nstreams;
> -        ogg->streams  = av_realloc(ogg->streams,
> -                                   ogg->nstreams * sizeof(*ogg->streams));
> -
> -        if (ogg->streams) {
> +        if ((err = av_reallocp_array(&ogg->streams, ogg->nstreams,
> +                                     sizeof(*ogg->streams))) < 0) {
> +            ogg->nstreams = 0;
> +            return err;
> +        } else
>              memcpy(ogg->streams, ost->streams,
>                     ost->nstreams * sizeof(*ogg->streams));
> -        } else {
> -            av_free(old_streams);
> -            ogg->nstreams = 0;
> -        }
>      }

This changes behavior considerably.  The av_free is gone and the memcpy
done in a different case.

> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2569,14 +2569,11 @@ AVStream *avformat_new_stream(AVFormatContext *s, 
> AVCodec *c)
>  {
>      AVStream *st;
>      int i;
> -    AVStream **streams;
>  
> -    if (s->nb_streams >= INT_MAX/sizeof(*streams))
> +    if (av_reallocp_array(&s->streams, s->nb_streams + 1, 
> sizeof(*s->streams)) < 0) {
> +        s->nb_streams = 0;
>          return NULL;
> -    streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));
> -    if (!streams)
> -        return NULL;
> -    s->streams = streams;
> +    }

I'm not entirely sure it's safe to fold the INT_MAX check into
av_reallocp_array().

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to