PR #24919 opened by RaHehl
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24919
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24919.patch

Since 62006041cc, a complete chunked response can end with "Input/output error" 
instead of EOF, because filesize stays UINT64_MAX. Record the body size at the 
terminating chunk unless it is already known.

```
ffmpeg -multiple_requests 0 -i http://host/chunked.mp3 -f null -
Error during demuxing: Input/output error
```
(`-multiple_requests 0` is the release/9.0 default; the CLI still exits 0 
without `-xerror`.)

Tested against a local server on master and release/9.0:

| | before | after |
|---|---|---|
| complete chunked: 9.0 default, master `-multiple_requests 0` | EIO | EOF |
| complete chunked, 200 + `Accept-Ranges`: master default | EIO | EOF |
| complete chunked, `-reconnect 1 -reconnect_streamed 1` | re-requested 
repeatedly | 1 request, EOF |
| truncated chunked 206 (`-request_size 65536`) | EIO | EIO |
| truncated Content-Length | "Stream ends prematurely" | same |

HLS (persistent connections, chunked and Content-Length segments) decodes 
identically before and after. FATE passes; it only covers HTTP status-line 
parsing, not transfers.

#24825 rewrites the same terminating-chunk block but leaves filesize unknown 
there, so whichever lands second needs a small rebase.

Found via https://github.com/home-assistant/core/issues/184600 (TTS audio 
served chunked).



>From 30f32ed159c15971a46894a987efce3845826ea1 Mon Sep 17 00:00:00 2001
From: Raphael Hehl <[email protected]>
Date: Wed, 7 Oct 2026 08:14:33 +0200
Subject: [PATCH] avformat/http: return EOF after the last chunk of a chunked
 response

Since 62006041cc ("avformat/http: don't return EOF unless we actually
read all bytes"), the end of a complete chunked response counts as
premature, because filesize stays UINT64_MAX. With multiple_requests
disabled (the release/9.0 default), the read after the terminating
chunk returns AVERROR(EIO). Otherwise (the master default since
ee2bc31032), a 200 response with Accept-Ranges fails the same way, and
-reconnect 1 -reconnect_streamed 1 requests the body again.

Record the body size at the terminating chunk unless it is already
known.

Regression since: 62006041cc
Signed-off-by: Raphael Hehl <[email protected]>
---
 libavformat/http.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/http.c b/libavformat/http.c
index b7ae56f723..a1f0954784 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1864,6 +1864,10 @@ static int http_buf_read(URLContext *h, uint8_t *buf, 
int size)
                    "Chunked encoding data size: %"PRIu64"\n",
                     s->chunksize);
 
+            /* terminating chunk: the body is complete */
+            if (!s->chunksize && s->filesize == UINT64_MAX)
+                s->filesize = s->off;
+
             if (!s->chunksize && s->multiple_requests) {
                 http_get_line(s, line, sizeof(line)); // read empty chunk
                 s->chunkend = 1;
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to