diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-03-25 08:52:09 +0300 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-05-20 11:51:30 +0300 |
commit | 0a4e978f35dd78668cf525be61e3b26a354db769 (patch) | |
tree | 8927f5661fafbeda2719ec59510f6a9fbafe2a91 | |
parent | 26d1e77923f35bcd959249dd5a351e30a93a65f0 (diff) |
avformat/matroskadec: Improve forward compability
Matroska is built around the principle that a reader does not need to
understand everything in a file in order to be able to make use of it;
it just needs to ignore the data it doesn't know about.
Our demuxer typically follows this principle, but there is one important
instance where it does not: A Block belonging to a TrackEntry with no
associated stream is treated as invalid data (i.e. the demuxer will try
to resync to the next level 1 element because it takes this as a sign
that it has lost sync). Given that we do not create streams if we don't
know or don't support the type of the TrackEntry, this impairs this
demuxer's forward compability.
Furthermore, ignoring Blocks belonging to a TrackEntry without
corresponding stream can (in future commits) also be used to ignore
TrackEntries with obviously bogus entries without affecting the other
TrackEntries (by not creating a stream for said TrackEntry).
Finally, given that matroska_find_track_by_num() already emits its own
error message in case there is no TrackEntry with a given TrackNumber,
the error message (with level AV_LOG_INFO) for this can be removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit b577968cabae4a0927adcf5d7c24fca5a7a8385d)
-rw-r--r-- | libavformat/matroskadec.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3cf4296f8d..938ba2cdb2 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -3563,13 +3563,16 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf size -= n; track = matroska_find_track_by_num(matroska, num); - if (!track || !track->stream) { - av_log(matroska->ctx, AV_LOG_INFO, - "Invalid stream %"PRIu64"\n", num); + if (!track || size < 3) return AVERROR_INVALIDDATA; - } else if (size < 3) - return AVERROR_INVALIDDATA; - st = track->stream; + + if (!(st = track->stream)) { + av_log(matroska->ctx, AV_LOG_VERBOSE, + "No stream associated to TrackNumber %"PRIu64". " + "Ignoring Block with this TrackNumber.\n", num); + return 0; + } + if (st->discard >= AVDISCARD_ALL) return res; av_assert1(block_duration != AV_NOPTS_VALUE); |