aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-03-09 14:59:44 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-03-21 01:52:52 +0100
commit93a0682b1d73f114720cd5c5bd69740546f78cdb (patch)
tree05d01f47469fb00762177a432b2cd9c0392eed7c
parent0e16c3843a3b2cd06b90898c04d85ed3d82266bb (diff)
downloadffmpeg-93a0682b1d73f114720cd5c5bd69740546f78cdb.tar.gz
ffmdec: limit the backward seek to the last resync position
If resyncing leads to the same position as previously, it will again lead to a resync attempt, resulting in an infinite loop. Thus don't seek back beyond the last syncpoint. Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 6b8263b03ab3d16d70525ae1893cb106be7852f1) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/ffmdec.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index ee34e73451..33bbde04b0 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -82,6 +82,7 @@ static int ffm_read_data(AVFormatContext *s,
FFMContext *ffm = s->priv_data;
AVIOContext *pb = s->pb;
int len, fill_size, size1, frame_offset, id;
+ int64_t last_pos = -1;
size1 = size;
while (size > 0) {
@@ -101,9 +102,11 @@ static int ffm_read_data(AVFormatContext *s,
avio_seek(pb, tell, SEEK_SET);
}
id = avio_rb16(pb); /* PACKET_ID */
- if (id != PACKET_ID)
+ if (id != PACKET_ID) {
if (ffm_resync(s, id) < 0)
return -1;
+ last_pos = avio_tell(pb);
+ }
fill_size = avio_rb16(pb);
ffm->dts = avio_rb64(pb);
frame_offset = avio_rb16(pb);
@@ -117,7 +120,9 @@ static int ffm_read_data(AVFormatContext *s,
if (!frame_offset) {
/* This packet has no frame headers in it */
if (avio_tell(pb) >= ffm->packet_size * 3LL) {
- avio_seek(pb, -ffm->packet_size * 2LL, SEEK_CUR);
+ int64_t seekback = FFMIN(ffm->packet_size * 2LL, avio_tell(pb) - last_pos);
+ seekback = FFMAX(seekback, 0);
+ avio_seek(pb, -seekback, SEEK_CUR);
goto retry_read;
}
/* This is bad, we cannot find a valid frame header */