diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2011-12-10 11:51:41 +0100 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2011-12-10 13:19:24 +0100 |
commit | 2483f5369369eb6c347c348f8e2fdbe27d3f25ed (patch) | |
tree | 8fdc2f62e7a5a6480a5f31b92f0854fc0771b859 | |
parent | f5ecc4c616397d657aca9cceef396a0a281c53c9 (diff) | |
download | ffmpeg-2483f5369369eb6c347c348f8e2fdbe27d3f25ed.tar.gz |
mxfdec: do not try to use an obviously broken index.
Also fixes a memleak.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
-rw-r--r-- | libavformat/mxfdec.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 47717c6db5..2f501a9e9c 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -200,6 +200,7 @@ typedef struct { int current_edit_unit; int current_stream; int d10; + int broken_index; } MXFContext; enum MXFWrappingScheme { @@ -432,7 +433,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) /* TODO: better logic for this? * only files that lack all index segments prior to the essence need this */ - if (!s->pb->seekable && mxf->op != OPAtom || mxf->d10) + if (!s->pb->seekable && mxf->op != OPAtom || mxf->d10 || mxf->broken_index) return mxf_read_packet_old(s, pkt); if (mxf->current_stream >= s->nb_streams) { @@ -1077,16 +1078,23 @@ static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t of static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st) { int j, k, ret, nb_sorted_segments; - MXFIndexTableSegment **sorted_segments; + MXFIndexTableSegment **sorted_segments = NULL; int n_delta = track_id - 1; /* TrackID = 1-based stream index */ if (track_id < 1) { av_log(mxf->fc, AV_LOG_ERROR, "TrackID not positive: %i\n", track_id); - return AVERROR_INVALIDDATA; + ret = AVERROR_INVALIDDATA; + goto err_out; } if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments))) - return ret; + goto err_out; + + if (nb_sorted_segments <= 0) { + av_log(mxf->fc, AV_LOG_WARNING, "Empty index for stream %i\n", st->index); + ret = 0; + goto err_out; + } for (j = 0; j < nb_sorted_segments; j++) { int duration, sample_duration = 1, last_sample_size = 0; @@ -1110,6 +1118,12 @@ static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st) if (last_sample_size) duration++; } + if (duration <= 0) { + av_log(mxf->fc, AV_LOG_WARNING, "0 duration in index for stream %i\n", st->index); + ret = 0; + goto err_out; + } + for (k = 0; k < duration; k++) { int64_t pos; int size, flags = 0; @@ -1171,6 +1185,11 @@ static int mxf_parse_index(MXFContext *mxf, int track_id, AVStream *st) av_free(sorted_segments); return 0; + +err_out: + av_free(sorted_segments); + mxf->broken_index = 1; + return ret; } static int mxf_parse_structural_metadata(MXFContext *mxf) |