[FFmpeg-devel] [PATCH 1/3] nutdec: fix infinite resync loops

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Wed May 20 00:49:49 CEST 2015


nut->last_syncpoint_pos doesn't necessarily change between resync
attempts, so find_any_startcode can return the same startcode again.

Thus remember where the last resync happened and don't try to resync
before that.

This can't be done locally in nut_read_packet, because this wouldn't
prevent infinite resync loops, where after the resync a packet is
returned and while reading a following packet the resync happens again.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
---
 libavformat/nut.h    | 1 +
 libavformat/nutdec.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/nut.h b/libavformat/nut.h
index 943081c..0c678a5 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -102,6 +102,7 @@ typedef struct NUTContext {
     unsigned int max_distance;
     unsigned int time_base_count;
     int64_t last_syncpoint_pos;
+    int64_t last_resync_pos;
     int header_count;
     AVRational *time_base;
     struct AVTreeNode *syncpoints;
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 2762db2..a75587f 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -1124,7 +1124,8 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
         default:
 resync:
             av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", pos);
-            tmp = find_any_startcode(bc, nut->last_syncpoint_pos + 1);
+            tmp = find_any_startcode(bc, FFMAX(nut->last_syncpoint_pos, nut->last_resync_pos) + 1);
+            nut->last_resync_pos = avio_tell(bc);
             if (tmp == 0)
                 return AVERROR_INVALIDDATA;
             av_log(s, AV_LOG_DEBUG, "sync\n");
-- 
2.1.4


More information about the ffmpeg-devel mailing list