From 233b56270ed18056d74e71f020ff2e45b8b7d23d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 4 Jul 2025 15:56:52 +0200 Subject: [PATCH 1/5] avcodec/av1dec,libdav1d,wbmpdec: Avoid direct access to GetByteContext Signed-off-by: Andreas Rheinhardt --- libavcodec/av1dec.c | 2 +- libavcodec/libdav1d.c | 2 +- libavcodec/wbmpdec.c | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 8ff1bf394c5c5..dcbe4ef2ce779 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -1024,7 +1024,7 @@ FF_ENABLE_DEPRECATION_WARNINGS provider_oriented_code != 0x800) break; - ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer, + ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, bytestream2_get_bytes_left(&gb), avctx->err_recognition); if (ret < 0) { av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index f4cbc927b5eee..f24d00ca38cc8 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -576,7 +576,7 @@ FF_ENABLE_DEPRECATION_WARNINGS provider_oriented_code != 0x800) break; - res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer, + res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, bytestream2_get_bytes_left(&gb), c->err_recognition); if (res < 0) { av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); diff --git a/libavcodec/wbmpdec.c b/libavcodec/wbmpdec.c index 50c729047d44c..5a61510a885cb 100644 --- a/libavcodec/wbmpdec.c +++ b/libavcodec/wbmpdec.c @@ -72,7 +72,8 @@ static int wbmp_decode_frame(AVCodecContext *avctx, AVFrame *p, if (p->linesize[0] == (width + 7) / 8) bytestream2_get_buffer(&gb, p->data[0], height * ((width + 7) / 8)); else - readbits(p->data[0], width, height, p->linesize[0], gb.buffer, gb.buffer_end - gb.buffer); + readbits(p->data[0], width, height, p->linesize[0], + gb.buffer, bytestream2_get_bytes_left(&gb)); *got_frame = 1; From 16bf80f2a0e22b3d01dbe1cbc6e11f830b4b4ff4 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 11 Jul 2025 16:17:49 +0200 Subject: [PATCH 2/5] avcodec/encode: Simplify pixel format validity check Signed-off-by: Andreas Rheinhardt --- libavcodec/encode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 38833c566c614..b9782a058116e 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -551,7 +551,7 @@ static int encode_preinit_video(AVCodecContext *avctx) const enum AVPixelFormat *pix_fmts; int ret, i, num_pix_fmts; - if (!av_get_pix_fmt_name(avctx->pix_fmt)) { + if (!pixdesc) { av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n", avctx->pix_fmt); return AVERROR(EINVAL); From c40d83b82c745e58f8fc21d7d3a36fee1260a7df Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 11 Jul 2025 16:25:41 +0200 Subject: [PATCH 3/5] avcodec/encode: Ignore coded_{width,height} It is supposed to be unused by encoders. Signed-off-by: Andreas Rheinhardt --- libavcodec/encode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index b9782a058116e..0308c73630004 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -818,8 +818,8 @@ int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: frame->format = avctx->pix_fmt; if (frame->width <= 0 || frame->height <= 0) { - frame->width = FFMAX(avctx->width, avctx->coded_width); - frame->height = FFMAX(avctx->height, avctx->coded_height); + frame->width = avctx->width; + frame->height = avctx->height; } break; From 6343359e84c16996736ef3c65330a3639f912bfa Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 11 Jul 2025 16:27:34 +0200 Subject: [PATCH 4/5] avcodec/encode: Remove dead code Can be readded if needed (likely never). Signed-off-by: Andreas Rheinhardt --- libavcodec/encode.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 0308c73630004..2f789c5b7a9fc 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -814,24 +814,12 @@ int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame) { int ret; - switch (avctx->codec->type) { - case AVMEDIA_TYPE_VIDEO: - frame->format = avctx->pix_fmt; - if (frame->width <= 0 || frame->height <= 0) { - frame->width = avctx->width; - frame->height = avctx->height; - } + av_assert1(avctx->codec_type == AVMEDIA_TYPE_VIDEO); - break; - case AVMEDIA_TYPE_AUDIO: - frame->sample_rate = avctx->sample_rate; - frame->format = avctx->sample_fmt; - if (!frame->ch_layout.nb_channels) { - ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); - if (ret < 0) - return ret; - } - break; + frame->format = avctx->pix_fmt; + if (frame->width <= 0 || frame->height <= 0) { + frame->width = avctx->width; + frame->height = avctx->height; } ret = avcodec_default_get_buffer2(avctx, frame, 0); From a91284170935d6af00fe336178a42cba599f6ebe Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 11 Jul 2025 16:46:27 +0200 Subject: [PATCH 5/5] avcodec/encode: Remove redundant av_image_check_size2() The dimensions have already been checked during init. Signed-off-by: Andreas Rheinhardt --- libavcodec/encode.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 2f789c5b7a9fc..c12cb1aa096ba 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -18,12 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/emms.h" #include "libavutil/frame.h" -#include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" @@ -357,8 +355,6 @@ static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { if ((avctx->flags & AV_CODEC_FLAG_PASS1) && avctx->stats_out) avctx->stats_out[0] = '\0'; - if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) - return AVERROR(EINVAL); } if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET) {