This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch release/9.1
in repository ffmpeg.

The following commit(s) were added to refs/heads/release/9.1 by this push:
     new 19aaa5e6f0 avformat/http: treat unknown-length clean EOF as EOF, not 
EIO
19aaa5e6f0 is described below

commit 19aaa5e6f07dcb73cd8befff13cdf5a6eb85b8f1
Author:     Jun Zhao <[email protected]>
AuthorDate: Sat Nov 21 10:29:11 2026 +0800
Commit:     Jun Zhao <[email protected]>
CommitDate: Sun Nov 22 22:43:05 2026 +0000

    avformat/http: treat unknown-length clean EOF as EOF, not EIO
    
    A reply with Transfer-Encoding: chunked and no Content-Length leaves
    filesize == UINT64_MAX, so the length comparisons added by 62006041cc
    ("don't return EOF unless we actually read all bytes") are always true.
    Once the terminating chunk closes the connection, the next read hits
    `!s->hd` and returns AVERROR(EIO) instead of EOF, even though the whole
    body was delivered. dashdec.c's parse_manifest() then fails with
    "Unable to read to manifest". On release/9.1 the auto keep-alive default
    (-1) hides it, but multiple_requests=0 still fails.
    
    Guard the three length comparisons on != UINT64_MAX so a clean close of
    an unknown-length resource is EOF while a declared-length truncation
    still returns EIO. Retain the chunked-framing completeness checks (short
    chunk body, missing terminating 0 chunk, and missing final CRLF/trailers
    even with multiple_requests=0 stay EIO) and the failed-reopen handling
    in http_read_stream() (preserve reopen errors, map headerless EOF to EIO,
    and continue the bounded retry loop instead of reading the restored
    connection). Keep this branch's existing header-reading order and HEAD
    behavior unchanged.
    
    Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/26199
    (cherry picked from commit 6865eb18f88e884732aec2100282ea7c61c3a6cb)
    Signed-off-by: Jun Zhao <[email protected]>
---
 libavformat/http.c | 53 +++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 10 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 04ed992070..9c0541fd5c 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1839,8 +1839,14 @@ static int http_buf_read(URLContext *h, uint8_t *buf, 
int size)
             int err;
 
             do {
-                if ((err = http_get_line(s, line, sizeof(line))) < 0)
+                if ((err = http_get_line(s, line, sizeof(line))) < 0) {
+                    /* The peer closed before the next chunk header. That
+                     * includes a missing terminating 0 chunk, so a clean
+                     * TCP close is not a complete chunked message. */
+                    if (err == AVERROR_EOF)
+                        return AVERROR(EIO);
                     return err;
+                }
             } while (!*line);    /* skip CR LF from last chunk */
 
             s->chunksize = strtoull(line, NULL, 16);
@@ -1853,11 +1859,11 @@ static int http_buf_read(URLContext *h, uint8_t *buf, 
int size)
                 /* a partial reply that ends at its range end is continued */
                 int more = s->range_end && s->off == s->range_end &&
                            s->range_end < requested_end(s);
+                do {
+                    if ((err = http_get_line(s, line, sizeof(line))) < 0)
+                        return err == AVERROR_EOF ? AVERROR(EIO) : err;
+                } while (*line);
                 if (s->multiple_requests) {
-                    do {
-                        if ((err = http_get_line(s, line, sizeof(line))) < 0)
-                            return err;
-                    } while (*line);
                     s->chunkend = !more;
                 } else {
                     av_log(h, AV_LOG_DEBUG, "Last chunk received, closing 
conn\n");
@@ -1889,8 +1895,18 @@ static int http_buf_read(URLContext *h, uint8_t *buf, 
int size)
         if (s->off == target_end && target_end < file_end)
             return AVERROR(EAGAIN); /* reached end of content range */
         len = ffurl_read(s->hd, buf, size);
+        /* A chunk body that stops short of its declared size is not a
+         * clean end, even when the resource length is unknown. */
+        if (s->chunksize != UINT64_MAX && s->chunksize > 0 &&
+            (!len || len == AVERROR_EOF)) {
+            av_log(h, AV_LOG_ERROR,
+                   "Chunked encoding ended %"PRIu64" bytes early\n",
+                   s->chunksize);
+            return AVERROR(EIO);
+        }
         if ((!len || len == AVERROR_EOF) &&
-            (!s->willclose || s->chunksize == UINT64_MAX) && s->off < 
target_end) {
+            (!s->willclose || s->chunksize == UINT64_MAX) &&
+            target_end != UINT64_MAX && s->off < target_end) {
             av_log(h, AV_LOG_ERROR,
                    "Stream ends prematurely at %"PRIu64", should be 
%"PRIu64"\n",
                    s->off, target_end
@@ -1970,8 +1986,11 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
     if (s->end_of_resource)
         return AVERROR_EOF;
 
-    if (!s->hd)
-        return s->off < requested_end(s) ? AVERROR(EIO) : AVERROR_EOF;
+    if (!s->hd) {
+        uint64_t file_end = requested_end(s);
+        return file_end != UINT64_MAX && s->off < file_end
+               ? AVERROR(EIO) : AVERROR_EOF;
+    }
 
     if (s->end_chunked_post && !s->end_header) {
         err = http_read_header(h);
@@ -1989,7 +2008,11 @@ retry:
     while (read_ret < 0) {
         uint64_t target = h->is_streamed ? 0 : s->off;
         uint64_t file_end = requested_end(s);
-        bool is_premature = file_end > 0 && s->off < file_end;
+        /* Unknown length: a clean close is EOF. A transport error still
+         * means bytes are missing, so reconnect can recover them. */
+        bool is_premature = file_end > 0 && s->off < file_end &&
+                            (file_end != UINT64_MAX ||
+                             read_ret != AVERROR_EOF);
 
         if (read_ret == AVERROR_EXIT)
             break;
@@ -2033,7 +2056,17 @@ retry:
         reconnect_delay = 1 + 2*reconnect_delay;
         conn_attempts++;
         seek_ret = http_seek_internal(h, target, SEEK_SET, 1);
-        if (seek_ret >= 0 && seek_ret != target) {
+        /* A failed reopen restored the old connection. Keep the reopen error
+         * instead of reading old_hd (which would turn e.g. HTTP 503 into EOF),
+         * and map a headerless EOF to EIO so unknown-length streams still
+         * spend the remaining retry budget. */
+        if (seek_ret < 0) {
+            if (seek_ret == AVERROR_EXIT || seek_ret == AVERROR(EAGAIN))
+                return (int)seek_ret;
+            read_ret = seek_ret == AVERROR_EOF ? AVERROR(EIO) : (int)seek_ret;
+            continue;
+        }
+        if (seek_ret != target) {
             ffurl_closep(&s->hd);
             av_log(h, AV_LOG_ERROR, "Failed to reconnect at %"PRIu64".\n", 
target);
             return read_ret;

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to