[FFmpeg-cvslog] avcodec/ffv1enc: Use dummies to avoid UB pointer arithmetic
Andreas Rheinhardt
git at videolan.org
Thu Jul 3 19:50:43 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Jun 22 23:25:34 2025 +0200| [bdb4cd44e24c69ca8a0ad1cd8b3772c43a225e7f] | committer: Andreas Rheinhardt
avcodec/ffv1enc: Use dummies to avoid UB pointer arithmetic
Fixes the following FATE-tests when run under Clang-UBSan:
ffmpeg-loopback-decoding, lavf-mxf_ffv1,
vsynth{1,2,3,_lena}-ffv1-v{0,2}, vsynth1-ffv{1,2,3,_lena},
vsynth{1,2,3,_lena}-ffv1-v3-yuv{420p,422p10,444p16}
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bdb4cd44e24c69ca8a0ad1cd8b3772c43a225e7f
---
libavcodec/ffv1enc.c | 5 +++++
libavcodec/ffv1enc_template.c | 5 ++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 463f46e091..cc3a04903f 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -281,6 +281,8 @@ static int encode_plane(FFV1Context *f, FFV1SliceContext *sc,
int16_t *sample[3];
sc->run_index = 0;
+ sample[2] = sc->sample_buffer; // dummy to avoid UB pointer arithmetic
+
memset(sc->sample_buffer, 0, ring_size * (w + 6) * sizeof(*sc->sample_buffer));
for (y = 0; y < h; y++) {
@@ -1509,6 +1511,9 @@ static int encode_float32_rgb_frame(FFV1Context *f, FFV1SliceContext *sc,
sc->run_index = 0;
+ for (int p = 0; p < MAX_PLANES; ++p)
+ sample[p][2] = sc->sample_buffer32; // dummy to avoid UB pointer arithmetic
+
memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
(w + 6) * sizeof(*RENAME(sc->sample_buffer)));
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index aaf82159ee..0178c398e5 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -25,7 +25,7 @@
static av_always_inline int
RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc,
void *logctx,
- int w, TYPE *sample[3], int plane_index, int bits,
+ int w, TYPE *const sample[3], int plane_index, int bits,
int ac, int pass1)
{
PlaneContext *const p = &sc->plane[plane_index];
@@ -189,6 +189,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc,
sc->run_index = 0;
+ for (int p = 0; p < MAX_PLANES; ++p)
+ sample[p][2] = RENAME(sc->sample_buffer);
+
memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
(w + 6) * sizeof(*RENAME(sc->sample_buffer)));
More information about the ffmpeg-cvslog
mailing list