From f87323a35994ffb833945c6e67029c74629ed704 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sun, 14 Jun 2026 13:03:34 +0200 Subject: [PATCH] avformat/http: properly fall back on soft seek failure If the HTTP server still has stale bytes in the TCP receive buffer, but the underlying conection was already closed, then the http_open_cnx() call might fail even though we successfully drained the previous request. In this case, there is no proper fallback to a new connection, leading to sudden truncation. Sponsored-by: nxtedition AB Signed-off-by: Niklas Haas --- libavformat/http.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libavformat/http.c b/libavformat/http.c index ce98c01ae4..3d0656d046 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -2163,6 +2163,15 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo } remaining -= ret; } + + ret = http_open_cnx(h, &options); + if (ret >= 0) { + goto done; + } else { + /* fall back to normal reconnection */ + ffurl_closep(&s->hd); + old_hd = NULL; + } } else { /* can't soft seek; always open new connection */ old_hd = s->hd; @@ -2181,6 +2190,8 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo av_dict_free(&options); return ret; } + +done: av_dict_free(&options); ffurl_close(old_hd); return off;