On Wed, Jul 13, 2011 at 10:00:53AM +0200, Anton Khirnov wrote:
>
> 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?
it's set to 1 in that case (three lines above)
> > 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.
At least I can ignore seektable for zero frames reported file, so here's
somewhat simpler patch.
>From 2bca9c02f70d03336741d72a04e2a010fbb420ca Mon Sep 17 00:00:00 2001
From: Kostya Shishkov <[email protected]>
Date: Mon, 11 Jul 2011 15:13:39 +0200
Subject: [PATCH] Musepack SV7: try to read files without number of frames provided
---
libavformat/mpc.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index 0aec1e8..75b59e1 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -70,7 +70,15 @@ 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;
}
- c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+ if(c->fcount){
+ c->frames = av_malloc(c->fcount * sizeof(MPCFrame));
+ if(!c->frames){
+ av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n");
+ return AVERROR(ENOMEM);
+ }
+ }else{
+ av_log(s, AV_LOG_WARNING, "Container reports no frames\n");
+ }
c->curframe = 0;
c->lastframe = -1;
c->curbits = 8;
@@ -111,7 +119,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->fcount)
return -1;
if(c->curframe != c->lastframe + 1){
@@ -133,7 +141,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_seek(s->pb, pos, SEEK_SET);
size = ((size2 + curbits + 31) & ~31) >> 3;
- if(cur == c->frames_noted){
+ if(cur == c->frames_noted && c->fcount){
c->frames[cur].pos = pos;
c->frames[cur].size = size;
c->frames[cur].skip = curbits - 20;
@@ -146,7 +154,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->fcount;
pkt->data[2] = 0;
pkt->data[3] = 0;
--
1.7.0.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel