From 4cf1843664e1b5cf2b233668fb830e5ecaac7388 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Nov 2014 18:51:11 +0100 Subject: demux_mkv: check file type without actually reading data Do a minimal check on data read with stream_peek(). This could help with probing from unseekable streams in some situations. (We could check the entire EBML and Matroska headers, but probably not worth the trouble. We could also seek back to the start, which demux.c doesn't do, but which would work usually - also not worth the trouble.) --- demux/demux_mkv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 100447d1f7..36ca0277ba 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -1757,6 +1757,13 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check) int64_t start_pos; int64_t end_pos; + bstr start = stream_peek(s, 4); + uint32_t start_id; + for (int n = 0; n < start.len; n++) + start_id = (start_id << 8) | start.start[n]; + if (start_id != EBML_ID_EBML) + return -1; + if (!read_ebml_header(demuxer)) return -1; MP_VERBOSE(demuxer, "Found the head...\n"); -- cgit v1.2.3