PR #26338 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26338 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26338.patch
From 576af84e6352bff06d1f8f73ad56c8bfa98dbbbc Mon Sep 17 00:00:00 2001 From: Zhao Zhili <[email protected]> Date: Mon, 22 Jun 2026 20:36:10 +0800 Subject: [PATCH 01/15] fftools/ffmpeg: disable stdin interaction when fd 0 is closed When the parent process closes stdin before launching ffmpeg, fd 0 is left invalid. The first opened input file then reuses fd 0, and the read_key() poll in the transcode loop reads from that input instead of the terminal, stealing bytes and corrupting the stream. Fixes #23539 (cherry picked from commit 0b4798f7ab964e288241536175228179acb1410f) Signed-off-by: Michael Niedermayer <[email protected]> --- fftools/ffmpeg.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index b394243f599..d38acffbdfb 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -216,6 +216,16 @@ void term_init(void) #endif #if HAVE_TERMIOS_H + /* A closed fd 0 is later reused by the first opened input file. read_key() + * would then read from that input instead of the terminal and corrupt the + * stream, so disable interaction when fd 0 is not an open descriptor. + */ + if (stdin_interaction && fcntl(0, F_GETFD) == -1) { + av_log(NULL, AV_LOG_WARNING, + "fd 0 is not an open file descriptor, stdin interaction disabled\n"); + stdin_interaction = 0; + } + if (stdin_interaction) { struct termios tty; if (tcgetattr (0, &tty) == 0) { -- 2.54.1 From c780256808c64e098cc426c42201ae7952e20e75 Mon Sep 17 00:00:00 2001 From: Niklas Haas <[email protected]> Date: Fri, 6 Mar 2026 00:50:53 +0100 Subject: [PATCH 02/15] swscale/graph: ensure intermediate buffers have extra line padding This basically guarantees that optimized packed routines have enough space to write a few bytes past the end of the line. Signed-off-by: Niklas Haas <[email protected]> (cherry picked from commit 4af33ec41801b9834fbe6772f9c1e53c48e0cd0d) Signed-off-by: Michael Niedermayer <[email protected]> --- libswscale/graph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libswscale/graph.c b/libswscale/graph.c index 16846a0607c..13a4fe1cf07 100644 --- a/libswscale/graph.c +++ b/libswscale/graph.c @@ -63,7 +63,7 @@ static int frame_alloc_planes(AVFrame *dst, int padding[4]) return ret; const int align = av_cpu_max_align(); - const int aligned_w = FFALIGN(dst->width, align); + const int aligned_w = FFALIGN(dst->width + 1, align); /* add space for over-write */ ret = av_image_fill_linesizes(dst->linesize, dst->format, aligned_w); if (ret < 0) return ret; -- 2.54.1 From 8eab19b8985046feab01abb6e9922b99c743a420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Wed, 29 Jul 2026 22:00:39 +0200 Subject: [PATCH 03/15] avutil/hwcontext_opencl: don't fall through between mapping types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a mapping type is unavailable the case fell into the next hardware type's mapping function instead of returning ENOSYS. Signed-off-by: Kacper Michajłow <[email protected]> (cherry picked from commit 9674156cc6d008a05a4c6c06470f0284a892959d) Signed-off-by: Michael Niedermayer <[email protected]> --- libavutil/hwcontext_opencl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index 03f46238b21..e6aa8de60a3 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -2937,32 +2937,38 @@ static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst, case AV_PIX_FMT_DRM_PRIME: if (priv->beignet_drm_mapping_usable) return opencl_map_from_drm_beignet(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_VAAPI_BEIGNET case AV_PIX_FMT_VAAPI: if (priv->beignet_drm_mapping_usable) return opencl_map_from_vaapi(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_VAAPI_INTEL_MEDIA case AV_PIX_FMT_QSV: case AV_PIX_FMT_VAAPI: if (priv->qsv_mapping_usable) return opencl_map_from_qsv(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_DXVA2 case AV_PIX_FMT_DXVA2_VLD: if (priv->dxva2_mapping_usable) return opencl_map_from_dxva2(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_D3D11 case AV_PIX_FMT_D3D11: if (priv->d3d11_mapping_usable) return opencl_map_from_d3d11(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_DRM_ARM case AV_PIX_FMT_DRM_PRIME: if (priv->drm_arm_mapping_usable) return opencl_map_from_drm_arm(hwfc, dst, src, flags); + break; #endif #if HAVE_OPENCL_VIDEOTOOLBOX case AV_PIX_FMT_VIDEOTOOLBOX: -- 2.54.1 From 50d81a1b3c65a458c768383efbca2ef2f58bafdd Mon Sep 17 00:00:00 2001 From: Niklas Haas <[email protected]> Date: Sat, 29 Aug 2026 13:48:22 +0200 Subject: [PATCH 04/15] avcodec/j2kenc: init bitstream after writing SOP Otherwise, *sop remains uninitialized if the sop is written. Sponsored-by: nxtedition AB Signed-off-by: Niklas Haas <[email protected]> (cherry picked from commit f88b741dbf242864e0c47b58e59dcbd67207c74b) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/j2kenc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index cb6118924dd..174d59a0160 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -720,15 +720,16 @@ static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, in { int bandno, empty = 1; int i; - // init bitstream - *s->buf = 0; - s->bit_index = 0; - if (s->sop) { bytestream_put_be16(&s->buf, JPEG2000_SOP); bytestream_put_be16(&s->buf, 4); bytestream_put_be16(&s->buf, packetno); } + + // init bitstream + *s->buf = 0; + s->bit_index = 0; + // header if (!layno) { -- 2.54.1 From 1b9584f7e8e0d6ed684459416f3cf148967bb1a9 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt <[email protected]> Date: Thu, 16 Jul 2026 19:26:50 +0200 Subject: [PATCH 05/15] avformat/rtpdec: propagate SRTP setup errors to the caller ff_rtp_parse_set_crypto() was void and dropped the ff_srtp_set_crypto() return value. A rejected crypto suite therefore left srtp_enabled clear while RTSPStream.crypto_suite stayed set, and rtsp.c uses crypto_suite[0] as the sole guard for secure transport. The session could thus be negotiated as SRTP while the RTP actually went out unprotected. Return the error instead and let ff_rtsp_open_transport_ctx() abort SETUP rather than continue with a half-initialised SRTP context. Signed-off-by: Thomas Devoogdt <[email protected]> (cherry picked from commit 9cf34b031f489dcecad5c579d0a22a956918cf36) Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/rtpdec.c | 11 +++++++---- libavformat/rtpdec.h | 4 ++-- libavformat/rtsp.c | 15 +++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 88ec01bcc0f..13f4b78a800 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -584,11 +584,14 @@ void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, s->handler = handler; } -void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, - const char *params) +int ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, + const char *params) { - if (!ff_srtp_set_crypto(&s->srtp, suite, params)) - s->srtp_enabled = 1; + int ret = ff_srtp_set_crypto(&s->srtp, suite, params); + if (ret < 0) + return ret; + s->srtp_enabled = 1; + return 0; } static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index c06f44b86c0..0c2a293c9b3 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -45,8 +45,8 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, int payload_type, int queue_size); void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, const RTPDynamicProtocolHandler *handler); -void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, - const char *params); +int ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, + const char *params); int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **buf, int len); void ff_rtp_parse_close(RTPDemuxContext *s); diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 956a80fc865..e9dd730d245 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -925,10 +925,17 @@ int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) rtsp_st->dynamic_protocol_context, rtsp_st->dynamic_handler); } - if (rtsp_st->crypto_suite[0]) - ff_rtp_parse_set_crypto(rtsp_st->transport_priv, - rtsp_st->crypto_suite, - rtsp_st->crypto_params); + if (rtsp_st->crypto_suite[0]) { + int ret = ff_rtp_parse_set_crypto(rtsp_st->transport_priv, + rtsp_st->crypto_suite, + rtsp_st->crypto_params); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, + "SRTP setup failed for suite '%s'\n", + rtsp_st->crypto_suite); + return ret; + } + } } return 0; -- 2.54.1 From 4d9a0883c0a8adebcdfa9789e31c012f51bd2651 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Tue, 15 Sep 2026 06:18:17 +0200 Subject: [PATCH 06/15] configure: select bswapdsp for the h264 and vvc decoders Found during triage/review of the security report 6f1DsDI0TxJu (cherry picked from commit 9449b1ae68d16a0cdad3460fd14b8989ebb3eff9) Signed-off-by: Michael Niedermayer <[email protected]> --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index dc7ec572673..03b3c4d6d19 100755 --- a/configure +++ b/configure @@ -3215,7 +3215,7 @@ h263_encoder_select="h263dsp mpegvideoenc" h263i_decoder_select="h263_decoder" h263p_decoder_select="h263_decoder" h263p_encoder_select="h263_encoder" -h264_decoder_select="cabac golomb h264chroma h264dsp h264parse h264pred h264qpel h264_sei videodsp" +h264_decoder_select="bswapdsp cabac golomb h264chroma h264dsp h264parse h264pred h264qpel h264_sei videodsp" h264_decoder_suggest="error_resilience" hap_decoder_select="snappy texturedsp" hap_encoder_deps="libsnappy" @@ -3363,7 +3363,7 @@ vp6f_decoder_select="vp6_decoder" vp7_decoder_select="h264pred videodsp vp8dsp" vp8_decoder_select="h264pred videodsp vp8dsp" vp9_decoder_select="videodsp vp9_parser cbs_vp9 vp9_superframe_split_bsf" -vvc_decoder_select="cabac cbs_h266 golomb videodsp vvc_sei" +vvc_decoder_select="bswapdsp cabac cbs_h266 golomb videodsp vvc_sei" wcmv_decoder_select="inflate_wrapper" webp_decoder_select="vp8_decoder" webp_anim_decoder_select="vp8_decoder" -- 2.54.1 From 076fd43b95ad3c03bc307eaa6f82405fa1746605 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 21 Sep 2026 23:16:45 +0200 Subject: [PATCH 07/15] avfilter/dnn_filter_common: free the options of the DNN child contexts Found during triage/review of the security report WobrPAzJQZg5 Fixes: memleak (cherry picked from commit 1281c683d30665414bb62fe5325e19fc552ccb96) Signed-off-by: Michael Niedermayer <[email protected]> --- libavfilter/dnn_filter_common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/dnn_filter_common.c b/libavfilter/dnn_filter_common.c index 73c5e6b33cf..ffa93835489 100644 --- a/libavfilter/dnn_filter_common.c +++ b/libavfilter/dnn_filter_common.c @@ -233,6 +233,8 @@ void ff_dnn_uninit(DnnContext *ctx) if (ctx->dnn_module) { (ctx->dnn_module->free_model)(&ctx->model); } + for (void *child = NULL; (child = ff_dnn_child_next(ctx, child));) + av_opt_free(child); if (ctx->model_outputnames) { for (int i = 0; i < ctx->nb_outputs; i++) av_free(ctx->model_outputnames[i]); -- 2.54.1 From cd691b86649c23c3524f3ec4d87e89b813893317 Mon Sep 17 00:00:00 2001 From: Thomas Devoogdt <[email protected]> Date: Sun, 19 Jul 2026 19:23:52 +0200 Subject: [PATCH 08/15] avformat/tls_gnutls, tls_openssl: fix AVERROR_EXIT in write callbacks Returning 0 from a TLS write callback means "0 bytes sent", not "abort". GnuTLS therefore retries the write forever, and OpenSSL reports success while silently dropping the record. Report an error instead: errno = EINTR, as required by the GnuTLS transport callback contract, and c->io_err for OpenSSL, so that an interrupted ffurl_write() propagates to the caller rather than hanging or losing data. Signed-off-by: Thomas Devoogdt <[email protected]> (cherry picked from commit 39cfc744bfb1e8a94f77419cf316ef731b214daf) Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/tls_gnutls.c | 7 ++++--- libavformat/tls_openssl.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c index aedbc66e56c..c40c2cd7f35 100644 --- a/libavformat/tls_gnutls.c +++ b/libavformat/tls_gnutls.c @@ -475,9 +475,10 @@ static ssize_t gnutls_url_push(gnutls_transport_ptr_t transport, int ret = ffurl_write(uc, buf, len); if (ret >= 0) return ret; - if (ret == AVERROR_EXIT) - return 0; - if (ret == AVERROR(EAGAIN)) { + if (ret == AVERROR_EXIT) { + /* Use EINTR, not 0: returning 0 would cause GnuTLS to busy-spin. */ + errno = EINTR; + } else if (ret == AVERROR(EAGAIN)) { errno = EAGAIN; } else { errno = EIO; diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index 48b4a2226a0..f8774b14664 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -572,8 +572,9 @@ static int url_bio_bwrite(BIO *b, const char *buf, int len) return ret; BIO_clear_retry_flags(b); if (ret == AVERROR_EXIT) - return 0; - if (ret == AVERROR(EAGAIN)) + /* Don't return 0: that signals success and silently drops the data. */ + c->io_err = ret; + else if (ret == AVERROR(EAGAIN)) BIO_set_retry_write(b); else c->io_err = ret; -- 2.54.1 From afadceaed480d514f5c68ac919eb9192a557f51c Mon Sep 17 00:00:00 2001 From: Romain Beauxis <[email protected]> Date: Sun, 1 Nov 2026 10:54:42 -0600 Subject: [PATCH 09/15] avcodec/opus/rc: avoid a 32-bit shift when flushing raw bits ff_opus_rc_enc_end() pads the raw bits to a full word, which asks ff_opus_rc_put_raw() for 32 bits when the cache is empty and shifts a 32-bit value by 32. Use the value whole when all 32 bits fit, which writes the same output without the undefined shift that aborts with --assert-level=2. (cherry picked from commit b21727ae6f097b9ca31cd0167e2d006dc9c09e63) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/opus/rc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/opus/rc.c b/libavcodec/opus/rc.c index 57ac272934d..f64078af3d2 100644 --- a/libavcodec/opus/rc.c +++ b/libavcodec/opus/rc.c @@ -163,7 +163,7 @@ void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count) const int to_write = FFMIN(32 - rc->rb.cachelen, count); rc->total_bits += count; - rc->rb.cacheval |= av_zero_extend(val, to_write) << rc->rb.cachelen; + rc->rb.cacheval |= (to_write < 32 ? av_zero_extend(val, to_write) : val) << rc->rb.cachelen; rc->rb.cachelen = (rc->rb.cachelen + to_write) % 32; if (!rc->rb.cachelen && count) { @@ -171,7 +171,7 @@ void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count) rc->rb.bytes += 4; rc->rb.position -= 4; rc->rb.cachelen = count - to_write; - rc->rb.cacheval = av_zero_extend(val >> to_write, rc->rb.cachelen); + rc->rb.cacheval = to_write < 32 ? av_zero_extend(val >> to_write, rc->rb.cachelen) : 0; av_assert0(rc->rng_cur < rc->rb.position); } } -- 2.54.1 From fb520ca98e01ab19a5fca10abe39900537dfa3b6 Mon Sep 17 00:00:00 2001 From: Ruk Doe <[email protected]> Date: Sat, 10 Oct 2026 15:50:10 +0900 Subject: [PATCH 10/15] avcodec/libaribcaption: iterate bitmap rects over images, not regions The bitmap path allocated one rect per rendered image but filled them, freed them and placed them by looping over the caption regions. The renderer does not draw every region: with ignore_ruby it drops ruby regions, and it always drops regions that are too small to draw. A caption with one ordinary and one ruby region then wrote past the end of the rects array. Loop over the images instead. The renderer does not say which region an image comes from, so the CLUT can no longer be seeded from "its" region. Seed it from the colors of every region that may be drawn; colors that are not seeded are still added from the image itself, as before. While at it, use bounded insertion for every CLUT seed color, including the text and background colors added in the character loop. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DdDiDRusmi6eD7qSrKBjHb Reported-by: Forgejo_Fairy Reference: #24992 (cherry picked from commit a7ef46558ef05ff8725dcbb0bf7743f4d16465d1) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/libaribcaption.c | 93 ++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/libavcodec/libaribcaption.c b/libavcodec/libaribcaption.c index 3fb7ae9f807..baddbe2bcaa 100644 --- a/libavcodec/libaribcaption.c +++ b/libavcodec/libaribcaption.c @@ -250,58 +250,37 @@ static uint8_t clut_pick_or_set(ARIBCaptionContext *ctx, int r, int g, int b, in return c; } -/* initialize CLUT with each character colors */ -static void clut_init(ARIBCaptionContext *ctx, aribcc_caption_region_t *region) +/* initialize CLUT with only the transparent color */ +static void clut_reset(ARIBCaptionContext *ctx) { - aribcc_color_t text_color, back_color, stroke_color; - uint32_t rgba; - ctx->clut[0] = CLUT_RGBA(0,0,0,0); /* transparent */ memset(ctx->clut_alpha, 0, sizeof(ctx->clut_alpha)); ctx->clut_alpha[0] = 0xFF; ctx->clut_idx = 1; ctx->clut_overflow = 0; - text_color = region->chars[0].text_color; - back_color = region->chars[0].back_color; - stroke_color = region->chars[0].stroke_color; - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(text_color, ARIBC_ALPHA_DEFAULT_FRONT); - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(back_color, ARIBC_ALPHA_DEFAULT_BACK); - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(stroke_color, ARIBC_ALPHA_DEFAULT_FRONT); - if (clut_find(ctx, rgba) < 0) { - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - } +} - for (int i = 1; i < region->char_count; i++) { - if (region->chars[i].text_color != text_color) { - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(region->chars[i].text_color, - ARIBC_ALPHA_DEFAULT_FRONT); - if (clut_find(ctx, rgba) < 0) { - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - } - } - if (region->chars[i].back_color != back_color) { - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(region->chars[i].back_color, - ARIBC_ALPHA_DEFAULT_BACK); - if (clut_find(ctx, rgba) < 0) { - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - } - } - if (region->chars[i].stroke_color != stroke_color) { - rgba = ARIBCC_COLOR_TO_CLUT_RGBA(region->chars[i].stroke_color, - ARIBC_ALPHA_DEFAULT_FRONT); - if (clut_find(ctx, rgba) < 0) { - if (ctx->clut_idx < AVPALETTE_COUNT) - ctx->clut[ctx->clut_idx++] = rgba; - clut_set_alpha(ctx, CLUT_A(rgba)); - } - } +/* add a color to the CLUT unless it is already there or the CLUT is full */ +static void clut_add(ARIBCaptionContext *ctx, uint32_t rgba) +{ + if (clut_find(ctx, rgba) >= 0) + return; + if (ctx->clut_idx >= AVPALETTE_COUNT) { + ctx->clut_overflow++; + return; + } + ctx->clut[ctx->clut_idx++] = rgba; + clut_set_alpha(ctx, CLUT_A(rgba)); +} + +/* add the character colors of a region to the CLUT */ +static void clut_add_region(ARIBCaptionContext *ctx, aribcc_caption_region_t *region) +{ + for (int i = 0; i < region->char_count; i++) { + aribcc_caption_char_t *ch = ®ion->chars[i]; + clut_add(ctx, ARIBCC_COLOR_TO_CLUT_RGBA(ch->text_color, ARIBC_ALPHA_DEFAULT_FRONT)); + clut_add(ctx, ARIBCC_COLOR_TO_CLUT_RGBA(ch->back_color, ARIBC_ALPHA_DEFAULT_BACK)); + clut_add(ctx, ARIBCC_COLOR_TO_CLUT_RGBA(ch->stroke_color, ARIBC_ALPHA_DEFAULT_FRONT)); } } @@ -319,7 +298,7 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) { int ret = 0; AVSubtitle *sub = ctx->sub; - int status, rect_idx; + int status, rect_idx, image_count = 0; int old_width = ctx->frame_width; int old_height = ctx->frame_height; @@ -397,13 +376,14 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) return 0; } + image_count = ctx->render_result.image_count; sub->format = 0; /* graphic */ - sub->rects = av_calloc(ctx->render_result.image_count, sizeof(*sub->rects)); + sub->rects = av_calloc(image_count, sizeof(*sub->rects)); if (!sub->rects) { ret = AVERROR(ENOMEM); goto fail; } - for (int i = 0; i < ctx->render_result.image_count; i++) { + for (int i = 0; i < image_count; i++) { sub->rects[i] = av_mallocz(sizeof(*sub->rects[i])); if (!sub->rects[i]) { ret = AVERROR(ENOMEM); @@ -411,12 +391,18 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) } } - for (rect_idx = 0; rect_idx < ctx->caption.region_count; rect_idx++) { + for (rect_idx = 0; rect_idx < image_count; rect_idx++) { AVSubtitleRect *rect = sub->rects[rect_idx]; aribcc_image_t *image = &ctx->render_result.images[rect_idx]; int w, h, shrink_height, dst_idx; - clut_init(ctx, &ctx->caption.regions[rect_idx]); + /* The renderer drops ruby regions with ignore_ruby and regions too + small to draw, without telling which region an image comes from. + Seed the CLUT with the colors of every region that may be drawn. */ + clut_reset(ctx); + for (int i = 0; i < ctx->caption.region_count; i++) + if (!(ctx->ignore_ruby && ctx->caption.regions[i].is_ruby)) + clut_add_region(ctx, &ctx->caption.regions[i]); rect->w = image->width * ctx->bitmap_plane_width / ctx->frame_width; rect->h = image->height * ctx->bitmap_plane_height / ctx->frame_height; @@ -476,7 +462,7 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) /* ARIB TR-B14 version 3.8 Fascicle 1-(2/2) Volume 3 [Section 4] */ /* No position information is provided for profile C */ rect->x = (ctx->frame_width - rect->w) / 2; - rect->y = ctx->frame_height - rect->h * (ctx->caption.region_count - rect_idx); + rect->y = ctx->frame_height - rect->h * (image_count - rect_idx); } else { rect->x = image->dst_x * ctx->bitmap_plane_width / ctx->frame_width; rect->y = image->dst_y * ctx->bitmap_plane_height / ctx->frame_height; @@ -485,8 +471,7 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) rect->linesize[0] = rect->w; rect->nb_colors = 256; - ff_dlog(ctx, "BITMAP subtitle%s (%d,%d) %dx%d -> (%d,%d) %dx%d [%d]: %d colors\n", - (ctx->caption.regions[rect_idx].is_ruby) ? " (ruby)" : "", + ff_dlog(ctx, "BITMAP subtitle (%d,%d) %dx%d -> (%d,%d) %dx%d [%d]: %d colors\n", image->dst_x, image->dst_y, image->width, image->height, rect->x, rect->y, rect->w, rect->h, rect_idx, ctx->clut_idx); @@ -499,7 +484,7 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx) fail: if (sub->rects) { - for (int i = 0; i < ctx->caption.region_count; i++) { + for (int i = 0; i < image_count; i++) { if (sub->rects[i]) { av_freep(&sub->rects[i]->data[0]); av_freep(&sub->rects[i]->data[1]); -- 2.54.1 From ba3d105a904c6c4ba005bef57dd2b87ce76e806b Mon Sep 17 00:00:00 2001 From: Uraza Aru <[email protected]> Date: Wed, 14 Oct 2026 02:14:02 +0500 Subject: [PATCH 11/15] avcodec/vulkan_encode_av1: use PRIMARY_REF_NONE for key frames primary_ref_frame is only set in the P and B branches, so key frames keep the initial 0. A shown key frame is error resilient: its header signals no primary reference and decoders start from the default CDFs for the frame's base_q_idx. With primary_ref_frame = 0, NVIDIA's encoder evidently starts from other CDFs; the two agree only while base_q_idx <= 20 (the first coefficient CDF q context). Above that, every key frame and everything after it is undecodable: dav1d reports a symbol decoder overread in the first tile and hardware decoders show garbage. This is why streams at modest bitrates (e.g. 1280x720 at 60 fps and 10 Mbit/s, key frame base_q_idx 39) failed while very high bitrates worked. Set primary_ref_frame to STD_VIDEO_AV1_PRIMARY_REF_NONE for key frames, as NVIDIA's Vulkan Video samples do. Tested on an RTX 4090 (Linux driver 615.78.08): CBR 2-60 Mbit/s and CQP 40-200 now decode, up to 2560x1440 at 120 fps and 3840x2160 at 60 fps. Fixes #25046. Assisted-by: Claude Opus 5.5 Signed-off-by: Uraza Aru <[email protected]> (cherry picked from commit c422dfdd677304ba2ba95c7bb046ff45a0b16e52) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/vulkan_encode_av1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/vulkan_encode_av1.c b/libavcodec/vulkan_encode_av1.c index d98b3a53b1d..19914b2c1e3 100644 --- a/libavcodec/vulkan_encode_av1.c +++ b/libavcodec/vulkan_encode_av1.c @@ -355,6 +355,7 @@ static int init_pic_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, av_assert0(pic->nb_refs[0] == 0 || pic->nb_refs[1]); ap->av1pic_info.frame_type = STD_VIDEO_AV1_FRAME_TYPE_KEY; ap->av1pic_info.refresh_frame_flags = 0xFF; + ap->av1pic_info.primary_ref_frame = STD_VIDEO_AV1_PRIMARY_REF_NONE; quantization->base_q_idx = enc->q_idx_idr; ap->slot = 0; ap->last_idr_frame = pic->display_order; -- 2.54.1 From 23925124957624d83b0cd2301a1288860e7ee866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Tue, 10 Nov 2026 11:25:02 +0100 Subject: [PATCH 12/15] avcodec/dxva2: limit the surface pool to 127 surfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DXVA specifications of H.264, HEVC and VP8/VP9 index surfaces with 7 bits and reserve 127 as the invalid index. Larger pools fail the av_assert0() in fill_picture_entry(). The DXVA AV1 specification uses 8 bit indices with 255 as the invalid one, but on AMD RX 9070 XT (32.0.32015.12012) AV1 inter frames decoded wrong whenever a texture index of 127 or higher was passed. The same array slices decoded correctly with the indices shifted below 127. Use 127 for every codec. Signed-off-by: Kacper Michajłow <[email protected]> (cherry picked from commit 35ce5707d0f8ac004d6e8fec85dffa294d09adfd) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/dxva2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c index 0ea45db8dff..8b53ecec1d6 100644 --- a/libavcodec/dxva2.c +++ b/libavcodec/dxva2.c @@ -653,6 +653,11 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx, return 0; } +/* The H.264, HEVC and VP9 picture parameters index surfaces with 7 bits and + * reserve 127 as the invalid index. The AV1 specification uses 8 bits with 255 + * as the invalid index, but indices >= 127 don't work on real hardware. */ +#define DXVA_MAX_SURFACES 127 + int ff_dxva2_decode_init(AVCodecContext *avctx) { FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx); @@ -681,6 +686,13 @@ int ff_dxva2_decode_init(AVCodecContext *avctx) goto fail; } + if (frames_ctx->initial_pool_size > DXVA_MAX_SURFACES) { + av_log(avctx, AV_LOG_ERROR, "The pool has %d surfaces, DXVA can address at most %d\n", + frames_ctx->initial_pool_size, DXVA_MAX_SURFACES); + ret = AVERROR(EINVAL); + goto fail; + } + #if CONFIG_D3D11VA if (sctx->pix_fmt == AV_PIX_FMT_D3D11) { AVD3D11VADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx; -- 2.54.1 From 4a598d84518754a11393add365772542dd5036c2 Mon Sep 17 00:00:00 2001 From: ohah <[email protected]> Date: Mon, 26 Oct 2026 10:05:43 +0000 Subject: [PATCH 13/15] avcodec/hevc: initialize inverse quantization tables through QP 75 rem6 and div6 each have room for 76 entries but only initialize the first 74. The remaining entries are implicitly zero, so QP 74 and 75 use an inverse quantization scale of 40 instead of 51 << 12 and 57 << 12, respectively. These indices are valid for 12-bit HEVC, where the bit-depth offset is 24. Append the missing remainder and quotient entries so high-QP 12-bit residuals use the scaling specified in H.265 section 8.6.3. Synthetic 12-bit 4:4:4 inputs exercising each index differ from x265's reconstruction in 16377 and 16379 samples before this change. Both outputs match the encoder reconstruction exactly after the fix. Signed-off-by: ohah <[email protected]> (cherry picked from commit c11f95d1878dc35c5618326c83c0c70090eb9713) Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/hevc/cabac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/hevc/cabac.c b/libavcodec/hevc/cabac.c index f6bde3028f3..59c99c5145e 100644 --- a/libavcodec/hevc/cabac.c +++ b/libavcodec/hevc/cabac.c @@ -1031,14 +1031,14 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, - 4, 5, 0, 1, 2, 3, 4, 5, 0, 1 + 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3 }; static const uint8_t div6[51 + 4 * 6 + 1] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, - 10, 10, 11, 11, 11, 11, 11, 11, 12, 12 + 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12 }; int qp_y = lc->qp_y; -- 2.54.1 From 1fa3d27edc2e2d7422ce49047cb7c32996855302 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Sat, 21 Nov 2026 15:55:40 -0800 Subject: [PATCH 14/15] avformat/cafdec: reject out of range priming and remainder frames Both are SInt32; larger values made initial_padding negative. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Baptiste Coudurier <[email protected]> (cherry picked from commit 359c82515228774eb683dffce9d623b6b4a2fa53) Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/cafdec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index fae4d7db5ec..ed86c092438 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -277,7 +277,9 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size) st->nb_frames = avio_rb64(pb); /* valid frames */ priming = avio_rb32(pb); /* priming frames */ caf->remainder = avio_rb32(pb); /* remainder frames */ - if (st->nb_frames < 0 || INT64_MAX - priming - caf->remainder < st->nb_frames) + /* both are SInt32 */ + if (priming > INT32_MAX || caf->remainder > INT32_MAX || + st->nb_frames < 0 || INT64_MAX - priming - caf->remainder < st->nb_frames) return AVERROR_INVALIDDATA; caf->frame_cnt = -(int64_t)priming; -- 2.54.1 From 8e43555aae3104d6ccfa8dbed1785cfcd8104b3e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Tue, 24 Nov 2026 19:55:48 +0100 Subject: [PATCH 15/15] Changelog: update Signed-off-by: Michael Niedermayer <[email protected]> --- Changelog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Changelog b/Changelog index 587a2e103dc..fb2ff45f89f 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,20 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. version 9.0.3: + avformat/cafdec: reject out of range priming and remainder frames + avcodec/hevc: initialize inverse quantization tables through QP 75 + avcodec/dxva2: limit the surface pool to 127 surfaces + avcodec/vulkan_encode_av1: use PRIMARY_REF_NONE for key frames + avcodec/libaribcaption: iterate bitmap rects over images, not regions + avcodec/opus/rc: avoid a 32-bit shift when flushing raw bits + avformat/tls_gnutls, tls_openssl: fix AVERROR_EXIT in write callbacks + avfilter/dnn_filter_common: free the options of the DNN child contexts + configure: select bswapdsp for the h264 and vvc decoders + avformat/rtpdec: propagate SRTP setup errors to the caller + avcodec/j2kenc: init bitstream after writing SOP + avutil/hwcontext_opencl: don't fall through between mapping types + swscale/graph: ensure intermediate buffers have extra line padding + fftools/ffmpeg: disable stdin interaction when fd 0 is closed avcodec/v210dec: keep SIMD stores within the decoded row aarch64/vvc: Fix 16-bit overflow in SME2 ALF luma filter avformat/rtpdec_av1: assemble the temporal unit in a packet of the PayloadContext instead of the caller's shared AVPacket -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
