From 6fd93ce27133a9d19be614d4ae68d026143f79d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kenneth=20Aafl=C3=B8y?= <kenneth@aafloy.net>
Date: Fri, 8 Jul 2005 09:14:05 +0000
Subject: [PATCH] =?UTF-8?q?avformat/av=5Fseek=5Fframe=5Fbinary=20with=20gr?=
 =?UTF-8?q?owing=20file=20patch=20by=20(Kenneth=20Aafl=C3=B8y:=20kenneth,?=
 =?UTF-8?q?=20aafloy=20net)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Originally committed as revision 4423 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavformat/utils.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 5dfeaaf36f7..6e7cd3e58c6 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1198,7 +1198,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
     AVInputFormat *avif= s->iformat;
     int64_t pos_min, pos_max, pos, pos_limit;
     int64_t ts_min, ts_max, ts;
-    int64_t start_pos;
+    int64_t start_pos, filesize;
     int index, no_change;
     AVStream *st;
 
@@ -1256,7 +1256,8 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
 
     if(ts_max == AV_NOPTS_VALUE){
         int step= 1024;
-        pos_max = url_fsize(&s->pb) - 1;
+        filesize = url_fsize(&s->pb);
+        pos_max = filesize - 1;
         do{
             pos_max -= step;
             ts_max = avif->read_timestamp(s, stream_index, &pos_max, pos_max + step);
@@ -1272,6 +1273,8 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
                 break;
             ts_max= tmp_ts;
             pos_max= tmp_pos;
+            if(tmp_pos >= filesize)
+                break;
         }
         pos_limit= pos_max;
     }
-- 
GitLab