Commit ffe49b0ca3 for ffmpeg
commit ffe49b0ca31d17d15e8b5af97249373db8ab23b8
Author: Kacper Michajłow <kasper93@gmail.com>
Date: Thu Oct 1 01:17:11 2026 +0200
avformat/libcurl: don't issue requests that cannot return data
Report EOF without a request when the requested offset is at or past
the known file size or the end offset, and report an error instead of
issuing the same request again when a reply that should continue the
transfer delivered no data.
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
diff --git a/libavformat/libcurl.c b/libavformat/libcurl.c
index 23d7f5f751..398e000bd1 100644
--- a/libavformat/libcurl.c
+++ b/libavformat/libcurl.c
@@ -657,6 +657,17 @@ static void start_request(CurlContext *c)
CURLcode cc;
int ret;
+ /* At or past the end of the file, report EOF without a request. */
+ if (c->probed && c->seekable &&
+ ((c->content_size >= 0 && c->request_start >= c->content_size) ||
+ (c->end_off > 0 && c->request_start >= c->end_off))) {
+ pthread_mutex_lock(&c->mutex);
+ update_status_locked(c, AVERROR_EOF, CURLE_OK);
+ pthread_cond_broadcast(&c->cond);
+ pthread_mutex_unlock(&c->mutex);
+ return;
+ }
+
if (!c->probed || c->seekable) {
int64_t start = c->request_start;
int64_t request_size = c->request_size;
@@ -773,6 +784,16 @@ static void on_done(CurlContext *c, CURLcode code)
if (c->end_off > 0)
file_end = FFMIN(file_end, c->end_off - 1);
if (c->seekable && c->request_end >= 0 && c->request_end < file_end) {
+ if (!received) {
+ av_log(c->h, AV_LOG_ERROR, "Server sent back no data at offset "
+ "%"PRId64"\n", c->request_start);
+ c->loop->num_errors++;
+ pthread_mutex_lock(&c->mutex);
+ update_status_locked(c, AVERROR(EIO), CURLE_OK);
+ pthread_cond_broadcast(&c->cond);
+ pthread_mutex_unlock(&c->mutex);
+ return;
+ }
c->is_initial = 0;
start_request(c);
return;