From ac7f67b3f23a63e463fb881d960bc8f31a230292 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 14 Nov 2019 12:59:14 +0100 Subject: demux_mkv, stream: attempt to improve behavior in unseekable streams stream_skip() semantics were kind of bad, especially after the recent change to the stream code. Forward stream_skip() calls could still trigger a seek and fail, even if it was supposed to actually skip data. (Maybe the idea that stream_skip() should try to seek is worthless in the first place.) Rename it to stream_seek_skip() (takes absolute position now because I think that's better), and make it always skip if the stream is marked as forward. While we're at it, make EOF detection more robust. I guess s->eof shouldn't exist at all, since it's valid only "sometimes". It should be removed... but not today. A 1-byte stream_read_peek() call is good to get the s->eof flag set to a correct value. --- demux/ebml.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'demux/ebml.c') diff --git a/demux/ebml.c b/demux/ebml.c index 44fa0c0793..143a5fe57b 100644 --- a/demux/ebml.c +++ b/demux/ebml.c @@ -180,14 +180,14 @@ int ebml_read_skip(struct mp_log *log, int64_t end, stream_t *s) if (len >= INT64_MAX - pos2 || (end > 0 && pos2 + len > end)) goto invalid; - if (!stream_skip(s, len)) + if (!stream_seek_skip(s, pos2 + len)) goto invalid; return 0; invalid: mp_err(log, "Invalid EBML length at position %"PRId64"\n", pos); - stream_seek(s, pos); + stream_seek_skip(s, pos); return 1; } @@ -198,6 +198,7 @@ int ebml_resync_cluster(struct mp_log *log, stream_t *s) { int64_t pos = stream_tell(s); uint32_t last_4_bytes = 0; + stream_read_peek(s, &(char){0}, 1); if (!s->eof) { mp_err(log, "Corrupt file detected. " "Trying to resync starting from position %"PRId64"...\n", pos); -- cgit v1.2.3