summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchcunningham <[email protected]>2019-02-06 16:12:51 -0800
committerMichael Niedermayer <[email protected]>2019-12-02 19:41:47 +0100
commit4123064b5f25f85f09a44ad57aa310877e334c93 (patch)
tree55e18437720a0a04e3a3f01b7b2471c22cec676e
parent5f0699d39abf75aaf26193b5ae736ae95ba83685 (diff)
avformat/mov.c: require tfhd to begin parsing trun
Detecting missing tfhd avoids re-using tfhd track info from the previous moof. For files with multiple tracks, this may make a mess of the avindex and fragindex, which can later trigger av_assert0 in mov_read_trun(). Reviewed-by: Derek Buitenhuis <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]> (cherry picked from commit 3ea87e5d9ea075d5b3c0f4f8c6c48e514b454cbe) Signed-off-by: Michael Niedermayer <[email protected]>
-rw-r--r--libavformat/isom.h1
-rw-r--r--libavformat/mov.c10
2 files changed, 11 insertions, 0 deletions
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 61a2b4fec4..b1fcf02f6e 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -76,6 +76,7 @@ typedef struct MOVAtom {
struct MOVParseTableEntry;
typedef struct MOVFragment {
+ int found_tfhd;
unsigned track_id;
uint64_t base_data_offset;
uint64_t moof_offset;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c5882be870..075930dacd 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -990,6 +990,9 @@ static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
+ // Set by mov_read_tfhd(). mov_read_trun() will reject files missing tfhd.
+ c->fragment.found_tfhd = 0;
+
if (!c->has_looked_for_mfra && c->use_mfra_for > 0) {
c->has_looked_for_mfra = 1;
if (pb->seekable) {
@@ -3366,6 +3369,8 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
MOVFragmentIndex* index = NULL;
int flags, track_id, i, found = 0;
+ c->fragment.found_tfhd = 1;
+
avio_r8(pb); /* version */
flags = avio_rb24(pb);
@@ -3500,6 +3505,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
unsigned entries, first_sample_flags = frag->flags;
int flags, distance, i, found_keyframe = 0, err;
+ if (!frag->found_tfhd) {
+ av_log(c->fc, AV_LOG_ERROR, "trun track id unknown, no tfhd was found\n");
+ return AVERROR_INVALIDDATA;
+ }
+
for (i = 0; i < c->fc->nb_streams; i++) {
if (c->fc->streams[i]->id == frag->track_id) {
st = c->fc->streams[i];