summaryrefslogtreecommitdiffstats
path: root/demux/ebml.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-03-28 00:01:17 +0100
committerwm4 <wm4@nowhere>2013-03-28 21:45:16 +0100
commitac1c5e6e18afc5043fa078803ef465bb4017c07a (patch)
tree5b82df5c32fd99f04b2ad6496474c5e4d2d84b41 /demux/ebml.h
parent3533ee3ae4b4dc2727dd499081d9edda55925749 (diff)
downloadmpv-ac1c5e6e18afc5043fa078803ef465bb4017c07a.tar.bz2
mpv-ac1c5e6e18afc5043fa078803ef465bb4017c07a.tar.xz
demux_mkv: improve robustness against broken files
Fixes test7.mkv from the Matroska test file collection, as well as some real broken files I've found in the wild. (Unfortunately, true recovery requires resetting the decoders and playback state with a manual seek, but it's still better than just exiting.) If there are broken EBML elements, try harder to skip them correctly. Do this by searching for the next cluster element. The cluster element intentionally has a long ID, so it's a suitable element for resynchronizing (mkvmerge does something similar). We know that data is corrupt if the ID or length fields of an element are malformed. Additionally, if skipping an unknown element goes past the end of the file, we assume it's corrupt and undo the seek. Do this because it often happens that corrupt data is interpreted as correct EBML elements. Since these elements will have a ridiculous values in their length fields due to the large value range that is possible (0-2^56-2), they will go past the end of the file. So instead of skipping them (which would result in playback termination), try to find the next cluster instead. (We still skip unknown elements that are within the file, as this is needed for correct operation. Also, we first execute the seek, because we don't really know where the file ends. Doing it this way is better for unseekable streams too, because it will still work in the non-error case.) This is done as special case in the packet reading function only. On the other hand, that's the only part of the file that's read after initialization is done.
Diffstat (limited to 'demux/ebml.h')
-rw-r--r--demux/ebml.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/demux/ebml.h b/demux/ebml.h
index 492144e5b7..be8573817a 100644
--- a/demux/ebml.h
+++ b/demux/ebml.h
@@ -99,6 +99,8 @@ double ebml_read_float (stream_t *s, uint64_t *length);
char *ebml_read_ascii (stream_t *s, uint64_t *length);
char *ebml_read_utf8 (stream_t *s, uint64_t *length);
int ebml_read_skip (stream_t *s, uint64_t *length);
+int ebml_read_skip_or_resync_cluster(stream_t *s, uint64_t *length);
+int ebml_resync_cluster(stream_t *s);
uint32_t ebml_read_master (stream_t *s, uint64_t *length);
int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx,