---
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;
+ }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));
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;
/* 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
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel