PR #25900 opened by Marti2203 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25900 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25900.patch
Follow-up to #25635, for the pre-existing zlib leak noted in the Forgejo_Fairy review there. `parse_content_encoding()` initialises `s->inflate_stream` as soon as a `Content-Encoding: gzip` or `deflate` header is read. If the open fails after that, `http_close()` is never called, since the context is only marked connected after a successful open, so the inflate state is leaked. A server that replies `HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\n` and closes the connection before the end of the headers makes `ffmpeg -i http://...` fail with "End of file", and LeakSanitizer reports 7160 bytes leaked per failed open on master. With this patch there is no leak report. The patch calls `inflateEnd()` in the error path of `http_open()`. `inflateEnd()` does nothing on a stream that was never initialised, as `http_close()` already relies on. It is based on master and is independent of #25635: it covers the client path now, and the single-client listen path once #25635 makes that path go through `bail_out`. Tested on an ASan build: fate-url and fate-http-status-line pass, and a gzip-encoded response is still decoded correctly. This issue was found during an LLM review (Forgejo_Fairy, #25635); the fix was verified manually. >From 4f2e5be0becfa7b8cd926d4add0e0001e8d4185f Mon Sep 17 00:00:00 2001 From: Martin Mirchev <[email protected]> Date: Tue, 10 Nov 2026 12:01:40 +0800 Subject: [PATCH] avformat/http: free the zlib state when the open fails parse_content_encoding() initialises the inflate stream as soon as a Content-Encoding: gzip or deflate header is read. If the open fails after that, e.g. because the connection ends before the end of the headers, http_close() is not called and the stream is never freed: LeakSanitizer reports 7160 bytes per failed open. Call inflateEnd() in the error path of http_open(). inflateEnd() is a no-op on a stream that was never initialised. Reported in the review of #25635. Signed-off-by: Martin Mirchev <[email protected]> --- libavformat/http.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/http.c b/libavformat/http.c index 2f4f522363a..a7854122f1b 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -864,6 +864,9 @@ static int http_open(URLContext *h, const char *uri, int flags, ret = http_open_cnx(h, options, 0); bail_out: if (ret < 0) { +#if CONFIG_ZLIB + inflateEnd(&s->inflate_stream); +#endif av_dict_free(&s->chained_options); av_dict_free(&s->cookie_dict); av_dict_free(&s->redirect_cache); -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
