PR #26243 opened by Jun Zhao (mypopydev)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26243
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26243.patch
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 and a transport error stays premature (so reconnect
can recover it).
Backport of the three != UINT64_MAX guard hunks from master's
6865eb18f88e884732aec2100282ea7c61c3a6cb. Unlike release/9.0, this
branch already has requested_end() and file_end, so the guard hunks
apply verbatim; the chunked-framing strictness, reconnect-loop and
HEAD changes from that commit are not part of this backport. This keeps
release/9.1 aligned with the release/9.0 backport (PR #26241).
Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/26199
Signed-off-by: Jun Zhao <[email protected]>
# Summary of changes
Briefly describe what this PR does and why.
<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).
Attached filenames must match the sample's filename:
```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->
>From b02d9da7f8d10fc1707bec55c4a8167f67ca4446 Mon Sep 17 00:00:00 2001
From: Jun Zhao <[email protected]>
Date: Sat, 21 Nov 2026 10:29:11 +0800
Subject: [PATCH] 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 and a transport error stays premature (so reconnect
can recover it).
Backport of the three != UINT64_MAX guard hunks from master's
6865eb18f88e884732aec2100282ea7c61c3a6cb. Unlike release/9.0, this
branch already has requested_end() and file_end, so the guard hunks
apply verbatim; the chunked-framing strictness, reconnect-loop and
HEAD changes from that commit are not part of this backport. This keeps
release/9.1 aligned with the release/9.0 backport (PR #26241).
Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/26199
Signed-off-by: Jun Zhao <[email protected]>
---
libavformat/http.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/libavformat/http.c b/libavformat/http.c
index 04ed9920704..51838244d7d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1890,7 +1890,8 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int
size)
return AVERROR(EAGAIN); /* reached end of content range */
len = ffurl_read(s->hd, buf, size);
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 +1971,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 +1993,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;
--
2.54.1
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]