[FFmpeg-cvslog] mxfdec: do not try to use an obviously broken index.

Reimar Döffinger git at videolan.org
Sat Dec 10 13:19:47 CET 2011


ffmpeg | branch: master | Reimar Döffinger <Reimar.Doeffinger at gmx.de> | Sat Dec 10 11:51:41 2011 +0100| [2483f5369369eb6c347c348f8e2fdbe27d3f25ed] | committer: Reimar Döffinger

mxfdec: do not try to use an obviously broken index.

Also fixes a memleak.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2483f5369369eb6c347c348f8e2fdbe27d3f25ed
---

 libavformat/mxfdec.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 47717c6..2f501a9 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)



More information about the ffmpeg-cvslog mailing list