[FFmpeg-cvslog] avcodec/dvenc: Check for unaligned pointers, strides
Andreas Rheinhardt
git at videolan.org
Sat May 31 02:52:51 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue May 27 16:30:11 2025 +0200| [61a70e8e9ef600e54d0fe1a48cda90c32b160049] | committer: Andreas Rheinhardt
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 at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=61a70e8e9ef600e54d0fe1a48cda90c32b160049
---
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. */
More information about the ffmpeg-cvslog
mailing list