[FFmpeg-cvslog] ftp: fix seeking beyond file size
Lukasz Marek
git at videolan.org
Sat Jun 8 16:05:29 CEST 2013
ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki at gmail.com> | Wed Jun 5 12:58:38 2013 +0200| [eeedca4b7f4b559d1d3630585a59841c24c7a2c2] | committer: Lukasz Marek
ftp: fix seeking beyond file size
adjust to ff* tools seek nature
Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eeedca4b7f4b559d1d3630585a59841c24c7a2c2
---
libavformat/ftp.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 3c32fcd..b59b5b6 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -591,7 +591,7 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
{
FTPContext *s = h->priv_data;
int err;
- int64_t new_pos;
+ int64_t new_pos, fake_pos;
av_dlog(h, "ftp protocol seek %"PRId64" %d\n", pos, whence);
@@ -617,13 +617,12 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
return AVERROR(EIO);
new_pos = FFMAX(0, new_pos);
- if (s->filesize >= 0)
- new_pos = FFMIN(s->filesize, new_pos);
+ fake_pos = s->filesize != -1 ? FFMIN(new_pos, s->filesize) : new_pos;
- if (new_pos != s->position) {
+ if (fake_pos != s->position) {
if ((err = ftp_abort(h)) < 0)
return err;
- s->position = new_pos;
+ s->position = fake_pos;
}
return new_pos;
}
@@ -652,8 +651,13 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size)
if (read >= 0) {
s->position += read;
if (s->position >= s->filesize) {
- if (ftp_abort(h) < 0)
+ /* server will terminate, but keep current position to avoid madness */
+ int64_t pos = s->position;
+ if (ftp_abort(h) < 0) {
+ s->position = pos;
return AVERROR(EIO);
+ }
+ s->position = pos;
}
}
if (read <= 0 && s->position < s->filesize && !h->is_streamed) {
More information about the ffmpeg-cvslog
mailing list