diff options
author | Lukasz Marek <lukasz.m.luki@gmail.com> | 2013-06-05 14:58:38 +0400 |
---|---|---|
committer | Lukasz Marek <lukasz.m.luki@gmail.com> | 2013-06-08 06:17:33 +0400 |
commit | eeedca4b7f4b559d1d3630585a59841c24c7a2c2 (patch) | |
tree | 3bfa7a59343080a16deb5eaa299e5f69411861ec /libavformat/ftp.c | |
parent | 4d617715c93d9f06ab38057639be6b5e0485fb3f (diff) |
ftp: fix seeking beyond file size
adjust to ff* tools seek nature
Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
Diffstat (limited to 'libavformat/ftp.c')
-rw-r--r-- | libavformat/ftp.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libavformat/ftp.c b/libavformat/ftp.c index 3c32fcd852..b59b5b6909 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) { |