1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

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@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-06-22 23:25:34 +02:00
parent 134c1d81a4
commit bdb4cd44e2
2 changed files with 9 additions and 1 deletions

View File

@@ -281,6 +281,8 @@ static int encode_plane(FFV1Context *f, FFV1SliceContext *sc,
int16_t *sample[3]; int16_t *sample[3];
sc->run_index = 0; 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)); memset(sc->sample_buffer, 0, ring_size * (w + 6) * sizeof(*sc->sample_buffer));
for (y = 0; y < h; y++) { for (y = 0; y < h; y++) {
@@ -1509,6 +1511,9 @@ static int encode_float32_rgb_frame(FFV1Context *f, FFV1SliceContext *sc,
sc->run_index = 0; 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 * memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
(w + 6) * sizeof(*RENAME(sc->sample_buffer))); (w + 6) * sizeof(*RENAME(sc->sample_buffer)));

View File

@@ -25,7 +25,7 @@
static av_always_inline int static av_always_inline int
RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc,
void *logctx, 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) int ac, int pass1)
{ {
PlaneContext *const p = &sc->plane[plane_index]; 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; 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 * memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
(w + 6) * sizeof(*RENAME(sc->sample_buffer))); (w + 6) * sizeof(*RENAME(sc->sample_buffer)));