On Tue, 12 Jul 2011 10:22:15 +0200, Kostya Shishkov <[email protected]> 
wrote:
> ---
>  libavformat/mpc.c |   26 +++++++++++++++++++++++---
>  1 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/mpc.c b/libavformat/mpc.c
> index 0aec1e8..ea6c90f 100644
> --- a/libavformat/mpc.c
> +++ b/libavformat/mpc.c
> @@ -41,6 +41,7 @@ typedef struct {
>      MPCFrame *frames;
>      int curbits;
>      int frames_noted;
> +    int unknown_num_frames;
>  } MPCContext;
>  
>  static int mpc_probe(AVProbeData *p)
> @@ -70,6 +71,13 @@ static int mpc_read_header(AVFormatContext *s, 
> AVFormatParameters *ap)
>          av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not 
> possible\n");
>          return -1;
>      }
> +    if(c->fcount){
> +        c->unknown_num_frames = 0;

Pointless, MPCContext is zeroed.

> +    }else{
> +        c->unknown_num_frames = 1;
> +        c->fcount             = 1;
> +        av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
> +    }
>      c->frames = av_malloc(c->fcount * sizeof(MPCFrame));

av_malloc(0), didn't we try to get rid of those?

>      c->curframe = 0;
>      c->lastframe = -1;
> @@ -91,7 +99,8 @@ static int mpc_read_header(AVFormatContext *s, 
> AVFormatParameters *ap)
>      av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
>      /* scan for seekpoints */
>      st->start_time = 0;
> -    st->duration = c->fcount;
> +    if(!c->unknown_num_frames)
> +        st->duration = c->fcount;

This will work just as well without the if().

>  
>      /* try to read APE tags */
>      if (s->pb->seekable) {
> @@ -111,7 +120,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket 
> *pkt)
>      int ret, size, size2, curbits, cur = c->curframe;
>      int64_t tmp, pos;
>  
> -    if (c->curframe >= c->fcount)
> +    if (c->curframe >= c->fcount && !c->unknown_num_frames)
>          return -1;
>  
>      if(c->curframe != c->lastframe + 1){
> @@ -134,6 +143,17 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket 
> *pkt)
>  
>      size = ((size2 + curbits + 31) & ~31) >> 3;
>      if(cur == c->frames_noted){
> +        if(c->unknown_num_frames){
> +            if(((int64_t)cur + 1) * sizeof(MPCFrame) >= UINT_MAX){
> +                av_log(s, AV_LOG_ERROR, "Too many frames encountered\n");
> +                return AVERROR(ENOMEM);
> +            }
> +            c->frames = av_realloc(c->frames, (cur + 1) * sizeof(MPCFrame));
> +            if(!c->frames){
> +                av_log(s, AV_LOG_ERROR, "Cannot grow seektable\n");
> +                return AVERROR(ENOMEM);
> +            }
> +        }
>          c->frames[cur].pos = pos;
>          c->frames[cur].size = size;
>          c->frames[cur].skip = curbits - 20;
> @@ -146,7 +166,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket 
> *pkt)
>          return AVERROR(EIO);
>  
>      pkt->data[0] = curbits;
> -    pkt->data[1] = (c->curframe > c->fcount);
> +    pkt->data[1] = (c->curframe > c->fcount) && !c->unknown_num_frames;
>      pkt->data[2] = 0;
>      pkt->data[3] = 0;
>  
> -- 
> 1.7.0.4

Overall I think this could be rewritten without trusting the frame count
at all (even if non-zero), but if you don't feel like doing it this
patch is surely better than nothing.

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

Reply via email to