path: root/demux/demux_mkv.c
diff options
authorwm4 <wm4@nowhere>2013-03-28 00:00:39 +0100
committerwm4 <wm4@nowhere>2013-03-28 00:00:39 +0100
commit3533ee3ae4b4dc2727dd499081d9edda55925749 (patch)
treec9c47b1db1b49a5938e68d2d9b300269fe189d9e /demux/demux_mkv.c
parent546ae23a0c40726a31a152da4fb6363c918065a0 (diff)
demux_mkv: fix skipping broken header elements
Fixes test4.mkv from the Matroska test file collection. demux_mkv_open() contains a loop that reads header elements. It starts by reading the EBML element ID with ebml_read_id(). If there is broken data in the header, ebml_read_id() might return EBML_ID_INVALID. However, that is not handled specially, and the code for handling unknown tags is invoked. This reads the EBML element length in order to skip data, which, if the EBML ID is broken, is entirely random. This caused a seek beyond the end of the file, making the demuxer fail. So don't skip any data if the EBML ID was invalid, and simply try to read the next element. ebml_read_id() reads at least one byte, so the parsing loop won't get stuck. All in all this is rather questionable, but since this affects error situations only, makes behavior a bit more robust (no random seeks), and actually fixes at least one sample, it's ok. libavformat's demuxer handled this.
Diffstat (limited to 'demux/demux_mkv.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 1e9a61806e..6d9ace28b6 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1066,7 +1066,7 @@ static int read_header_element(struct demuxer *demuxer, uint32_t id,
res = 2;
- if (!at_filepos)
+ if (!at_filepos && id != EBML_ID_INVALID)
ebml_read_skip(s, NULL);
return res;