From 49a1efb0b2f3a0370da3ea8175c5477fa1cb2a26 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 27 May 2025 16:30:11 +0200 Subject: [PATCH 2/7] avcodec/dvenc: Check for unaligned pointers, strides Fixes segfaults on systems where PixblockDSPContext.get_pixels really requires to be properly aligned (e.g. ARMv7). Before this commit input created by -filter_complex nullsrc=s=740x576:r=25,format=yuv420p,crop=w=720:x=2 led to crashes. (The unaligned strides are in violation of the AVFrame.linesize documentation, unaligned pointers itself do not seem to be prohibited for encoders.) Signed-off-by: Andreas Rheinhardt --- libavcodec/dvenc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c index c7fc930b4b..5ff114da9f 100644 --- a/libavcodec/dvenc.c +++ b/libavcodec/dvenc.c @@ -63,6 +63,8 @@ typedef struct DVEncContext { DVwork_chunk work_chunks[4 * 12 * 27]; int quant_deadzone; + + PixblockDSPContext pdsp; } DVEncContext; @@ -70,7 +72,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx) { DVEncContext *s = avctx->priv_data; FDCTDSPContext fdsp; - PixblockDSPContext pdsp; int ret; s->avctx = avctx; @@ -108,12 +109,10 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx) } memset(&fdsp,0, sizeof(fdsp)); - memset(&pdsp,0, sizeof(pdsp)); ff_fdctdsp_init(&fdsp, avctx); - ff_pixblockdsp_init(&pdsp, avctx); - s->get_pixels = pdsp.get_pixels; s->fdct[0] = fdsp.fdct; s->fdct[1] = fdsp.fdct248; + ff_pixblockdsp_init(&s->pdsp, avctx); #if !CONFIG_HARDCODED_TABLES { @@ -1201,6 +1200,13 @@ static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, DVEncContext *s = c->priv_data; int ret; + if ((uintptr_t)frame->data[0] & 7 || frame->linesize[0] & 7 || + (uintptr_t)frame->data[1] & 7 || frame->linesize[1] & 7 || + (uintptr_t)frame->data[2] & 7 || frame->linesize[2] & 7) + s->get_pixels = s->pdsp.get_pixels_unaligned; + else + s->get_pixels = s->pdsp.get_pixels; + if ((ret = ff_get_encode_buffer(c, pkt, s->sys->frame_size, 0)) < 0) return ret; /* Fixme: Only zero the part that is not overwritten later. */ -- 2.45.2