summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-05-17 00:29:49 +0200
committerJames Almer <jamrial@gmail.com>2019-06-23 00:47:50 -0300
commit36aceb6174a6a1c40014001ff73c4c30012b569d (patch)
treea73233cae34d5f58a3dce6d8cc5cc8290ea50be2 /libavformat/matroskadec.c
parent70baf729b536be532ef1de9a28b584f19e62eeeb (diff)
avformat/matroskadec: Get rid of cluster size field assumption
The earlier code relied on the length of clusters always being coded on eight bytes as was the behaviour of libavformat's Matroska muxer until recently. But given that our own Matroska muxer now (and mkvmerge from time immemorial) creates files that don't conform to this assumption, it is high time to get rid of this assumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 1b0db92595..09b5cf3a28 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3656,15 +3656,17 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s)
cluster_pos = s->streams[0]->index_entries[index].pos;
before_pos = avio_tell(s->pb);
while (1) {
- int64_t cluster_id = 0, cluster_length = 0;
+ uint64_t cluster_id, cluster_length;
+ int read;
AVPacket *pkt;
avio_seek(s->pb, cluster_pos, SEEK_SET);
// read cluster id and length
- ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id);
- ebml_read_length(matroska, matroska->ctx->pb, &cluster_length);
- if (cluster_id != 0xF43B675) { // done with all clusters
+ read = ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id);
+ if (read < 0 || cluster_id != 0xF43B675) // done with all clusters
+ break;
+ read = ebml_read_length(matroska, matroska->ctx->pb, &cluster_length);
+ if (read < 0)
break;
- }
avio_seek(s->pb, cluster_pos, SEEK_SET);
matroska->current_id = 0;
matroska_clear_queue(matroska);
@@ -3673,7 +3675,8 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s)
break;
}
pkt = &matroska->queue->pkt;
- cluster_pos += cluster_length + 12; // 12 is the offset of the cluster id and length.
+ // 4 + read is the length of the cluster id and the cluster length field.
+ cluster_pos += 4 + read + cluster_length;
if (!(pkt->flags & AV_PKT_FLAG_KEY)) {
rv = 0;
break;