1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

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 <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-05-27 16:30:11 +02:00
parent 1a7e802c8f
commit 61a70e8e9e

View File

@ -63,6 +63,8 @@ typedef struct DVEncContext {
DVwork_chunk work_chunks[4 * 12 * 27]; DVwork_chunk work_chunks[4 * 12 * 27];
int quant_deadzone; int quant_deadzone;
PixblockDSPContext pdsp;
} DVEncContext; } DVEncContext;
@ -70,7 +72,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
{ {
DVEncContext *s = avctx->priv_data; DVEncContext *s = avctx->priv_data;
FDCTDSPContext fdsp; FDCTDSPContext fdsp;
PixblockDSPContext pdsp;
int ret; int ret;
s->avctx = avctx; s->avctx = avctx;
@ -108,12 +109,10 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
} }
memset(&fdsp,0, sizeof(fdsp)); memset(&fdsp,0, sizeof(fdsp));
memset(&pdsp,0, sizeof(pdsp));
ff_fdctdsp_init(&fdsp, avctx); ff_fdctdsp_init(&fdsp, avctx);
ff_pixblockdsp_init(&pdsp, avctx);
s->get_pixels = pdsp.get_pixels;
s->fdct[0] = fdsp.fdct; s->fdct[0] = fdsp.fdct;
s->fdct[1] = fdsp.fdct248; s->fdct[1] = fdsp.fdct248;
ff_pixblockdsp_init(&s->pdsp, avctx);
#if !CONFIG_HARDCODED_TABLES #if !CONFIG_HARDCODED_TABLES
{ {
@ -1201,6 +1200,13 @@ static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt,
DVEncContext *s = c->priv_data; DVEncContext *s = c->priv_data;
int ret; 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) if ((ret = ff_get_encode_buffer(c, pkt, s->sys->frame_size, 0)) < 0)
return ret; return ret;
/* Fixme: Only zero the part that is not overwritten later. */ /* Fixme: Only zero the part that is not overwritten later. */