]> git.sesse.net Git - ffmpeg/commitdiff
avformat/mpegts: Shuffle avio_seek
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 7 May 2020 10:38:26 +0000 (12:38 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 17 May 2020 18:15:05 +0000 (20:15 +0200)
This avoids accessing an old, no longer valid buffer.
Fixes: out of array access
Fixes: crash_audio-2020
Found-by: le wu <shoulewoba@gmail.com>
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/mpegts.c

index 0833d62ea58ba7b27e9c961fb5c98ba8167bc33f..a065c61c40075b05d582a7ff2f47818547ca2ca7 100644 (file)
@@ -2881,15 +2881,16 @@ static int mpegts_resync(AVFormatContext *s, int seekback, const uint8_t *curren
     AVIOContext *pb = s->pb;
     int c, i;
     uint64_t pos = avio_tell(pb);
-
-    avio_seek(pb, -FFMIN(seekback, pos), SEEK_CUR);
+    int64_t back = FFMIN(seekback, pos);
 
     //Special case for files like 01c56b0dc1.ts
     if (current_packet[0] == 0x80 && current_packet[12] == 0x47) {
-        avio_seek(pb, 12, SEEK_CUR);
+        avio_seek(pb, 12 - back, SEEK_CUR);
         return 0;
     }
 
+    avio_seek(pb, -back, SEEK_CUR);
+
     for (i = 0; i < ts->resync_size; i++) {
         c = avio_r8(pb);
         if (avio_feof(pb))