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

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

commit 8bf82c567a61a37299dd907d75a1d4364fab14b8
Author:     Jun Zhao <[email protected]>
AuthorDate: Fri Aug 28 07:44:27 2026 +0800
Commit:     Michael Niedermayer <[email protected]>
CommitDate: Sat Sep 19 14:27:11 2026 +0200

    avformat: Restore the container channel layout after a failed decoder open
    
    avformat_find_stream_info() copies codec parameters from the decoder
    context after probing, including when avcodec_open2() has already
    failed. A failed avcodec_open2() zeroes the context channel layout via
    ff_codec_close() -> av_opt_free(), because ch_layout is an
    AV_OPT_TYPE_CHLAYOUT option. That empty layout is then written back
    onto codecpar and replaces the value the demuxer had already set from
    the container.
    
    This is reachable for codecs such as adpcm_psx that have no parser and
    do not set AVSTREAM_PARSE_*: the only source of the channel count is
    the demuxer header. It differs from codecs like mp3, where the decoder
    is expected to fill the layout.
    
    Restore the container channel layout when it was specified and the
    decoder result is unspecified, matching the existing restore of color
    metadata in parameters_from_context().
    
    See also:
    https://ffmpeg.org/pipermail/ffmpeg-devel/2024-November/335598.html
    
    Fixes: #24290
    Fixes: https://issues.oss-fuzz.com/issues/42536474
    Reported-by: DarĂ­o Clavijo
    Found-by: OSS-Fuzz
    Signed-off-by: Jun Zhao <[email protected]>
    (cherry picked from commit fd6dc624be1eaf447569df270eb0d8ac5e3d7518)
    Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavformat/demux.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 555399720c..1c72c19348 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2597,6 +2597,16 @@ static int parameters_from_context(AVFormatContext *ic, 
AVCodecParameters *par,
     if (par_tmp->chroma_location != AVCHROMA_LOC_UNSPECIFIED)
         par->chroma_location = par_tmp->chroma_location;
 
+    /* A failed avcodec_open2() zeroes ch_layout through
+     * ff_codec_close() -> av_opt_free(); do not copy that empty layout
+     * over a container-signaled one. Other AVOption types used here are
+     * integers and are not cleared. */
+    if (par_tmp->ch_layout.nb_channels > 0 && !par->ch_layout.nb_channels) {
+        ret = av_channel_layout_copy(&par->ch_layout, &par_tmp->ch_layout);
+        if (ret < 0)
+            goto fail;
+    }
+
     ret = 0;
 fail:
     avcodec_parameters_free(&par_tmp);

-- 
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