From 3b9e6a7333c1c8334e338394851e2e93f949e9e6 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 10 Sep 2023 13:35:29 +0200 Subject: [PATCH] avcodec/magicyuvenc: fix correlation buffers size when slices are used --- libavcodec/magicyuvenc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/magicyuvenc.c b/libavcodec/magicyuvenc.c index b166ec4f2f..427d4848e6 100644 --- a/libavcodec/magicyuvenc.c +++ b/libavcodec/magicyuvenc.c @@ -196,12 +196,6 @@ static av_cold int magy_encode_init(AVCodecContext *avctx) s->format = 0x6b; break; } - if (s->correlate) { - s->decorrelate_buf[0] = av_calloc(2U * avctx->height, FFALIGN(avctx->width, av_cpu_max_align())); - if (!s->decorrelate_buf[0]) - return AVERROR(ENOMEM); - s->decorrelate_buf[1] = s->decorrelate_buf[0] + avctx->height * FFALIGN(avctx->width, av_cpu_max_align()); - } ff_llvidencdsp_init(&s->llvidencdsp); @@ -216,6 +210,13 @@ static av_cold int magy_encode_init(AVCodecContext *avctx) if (!s->slices) return AVERROR(ENOMEM); + if (s->correlate) { + s->decorrelate_buf[0] = av_calloc(2U * (s->nb_slices * s->slice_height), FFALIGN(avctx->width, av_cpu_max_align())); + if (!s->decorrelate_buf[0]) + return AVERROR(ENOMEM); + s->decorrelate_buf[1] = s->decorrelate_buf[0] + (s->nb_slices * s->slice_height) * FFALIGN(avctx->width, av_cpu_max_align()); + } + s->bitslice_size = avctx->width * (s->slice_height + 2) + AV_INPUT_BUFFER_PADDING_SIZE; for (int n = 0; n < s->nb_slices; n++) { for (int i = 0; i < s->planes; i++) { @@ -375,7 +376,7 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane) const uint8_t *dst = sl->slice; PTable *counts = sl->counts; - memset(counts, 0, sizeof(*counts) * 256); + memset(counts, 0, sizeof(sl->counts)); count_usage(dst, AV_CEIL_RSHIFT(avctx->width, s->hshift[plane]), AV_CEIL_RSHIFT(s->slice_height, s->vshift[plane]), counts);