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

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

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

commit ac1c6e003f9e298536363e716750abc0c8f25b37
Author:     Jun Zhao <[email protected]>
AuthorDate: Sat Nov 21 08:17:42 2026 +0800
Commit:     Jun Zhao <[email protected]>
CommitDate: Sun Nov 22 09:08:24 2026 +0800

    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"; -multiple_requests 1 masks it.
    
    Guard the three length comparisons on != UINT64_MAX (adapted to
    release/9.0's s->filesize/target_end comparisons) 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 | 60 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 35f886fba7..b2c9d9bdd4 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1731,8 +1731,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);
@@ -1741,14 +1747,17 @@ static int http_buf_read(URLContext *h, uint8_t *buf, 
int size)
                    "Chunked encoding data size: %"PRIu64"\n",
                     s->chunksize);
 
-            if (!s->chunksize && s->multiple_requests) {
-                http_get_line(s, line, sizeof(line)); // read empty chunk
-                s->chunkend = 1;
-                return 0;
-            }
-            else if (!s->chunksize) {
-                av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n");
-                ffurl_closep(&s->hd);
+            if (!s->chunksize) {
+                do {
+                    if ((err = http_get_line(s, line, sizeof(line))) < 0)
+                        return err == AVERROR_EOF ? AVERROR(EIO) : err;
+                } while (*line);
+                if (s->multiple_requests) {
+                    s->chunkend = 1;
+                } else {
+                    av_log(h, AV_LOG_DEBUG, "Last chunk received, closing 
conn\n");
+                    ffurl_closep(&s->hd);
+                }
                 return 0;
             }
             else if (s->chunksize == UINT64_MAX) {
@@ -1775,8 +1784,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
@@ -1839,7 +1858,8 @@ static int http_read_stream(URLContext *h, uint8_t *buf, 
int size)
     int conn_attempts = 1;
 
     if (!s->hd)
-        return s->off < s->filesize ? AVERROR(EIO) : AVERROR_EOF;
+        return s->filesize != UINT64_MAX && s->off < s->filesize
+               ? AVERROR(EIO) : AVERROR_EOF;
 
     if (s->end_chunked_post && !s->end_header) {
         err = http_read_header(h);
@@ -1856,7 +1876,11 @@ retry:
     read_ret = http_buf_read(h, buf, size);
     while (read_ret < 0) {
         uint64_t target = h->is_streamed ? 0 : s->off;
-        bool is_premature = s->filesize > 0 && s->off < s->filesize;
+        /* Unknown length: a clean close is EOF. A transport error still
+         * means bytes are missing, so reconnect can recover it. */
+        bool is_premature = s->filesize > 0 && s->off < s->filesize &&
+                            (s->filesize != UINT64_MAX ||
+                             read_ret != AVERROR_EOF);
 
         if (read_ret == AVERROR_EXIT)
             break;
@@ -1895,7 +1919,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