diff mbox

[FFmpeg-devel] avformat/http: Do not try to make a new request when seeking past the end of the file

Message ID CABLWnS8y_gQA5wEaVA0xEqVGyA9un_kw56M9AY=2jsUq5JaVnw@mail.gmail.com
State New
Headers show

Commit Message

Vittorio Giovara Feb. 15, 2019, 4:34 p.m. UTC
From: Justin Ruggles <justin.ruggles@gmail.com>

This avoids making invalid HTTP Range requests for a byte range past the
known end of the file during a seek. Those requests generally return a HTTP
response of 416 Range Not Satisfiable, which causes an error response.

Reference: https://tools.ietf.org/html/rfc7233

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
---
 libavformat/http.c | 7 +++++++
 1 file changed, 7 insertions(+)

     old_buf_size = s->buf_end - s->buf_ptr;
     memcpy(old_buf, s->buf_ptr, old_buf_size);

Comments

Michael Niedermayer Feb. 15, 2019, 5:36 p.m. UTC | #1
On Fri, Feb 15, 2019 at 11:34:43AM -0500, Vittorio Giovara wrote:
> From: Justin Ruggles <justin.ruggles@gmail.com>
> 
> This avoids making invalid HTTP Range requests for a byte range past the
> known end of the file during a seek. Those requests generally return a HTTP
> response of 416 Range Not Satisfiable, which causes an error response.
> 
> Reference: https://tools.ietf.org/html/rfc7233
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> ---
>  libavformat/http.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index a0a0636cf2..1e40268599 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -1691,6 +1691,13 @@ static int64_t http_seek_internal(URLContext *h,
> int64_t off, int whence, int fo
>      if (s->off && h->is_streamed)
>          return AVERROR(ENOSYS);
> 
> +    /* do not try to make a new connection if seeking past the end of the
> file */

patch corrupted by newline


[...]
diff mbox

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index a0a0636cf2..1e40268599 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1691,6 +1691,13 @@  static int64_t http_seek_internal(URLContext *h,
int64_t off, int whence, int fo
     if (s->off && h->is_streamed)
         return AVERROR(ENOSYS);

+    /* do not try to make a new connection if seeking past the end of the
file */
+    if (s->end_off || s->filesize != UINT64_MAX) {
+        uint64_t end_pos = s->end_off ? s->end_off : s->filesize;
+        if (s->off >= end_pos)
+            return s->off;
+    }
+
     /* we save the old context in case the seek fails */