aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2021-08-14 16:45:02 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2021-10-05 23:19:39 +0200
commita0e38aceba43526cd01d27e16e83d51f7518622a (patch)
treec33c5a8a4c2a883ac8613bc245b27a507f006a71 /libavcodec
parent02fd9353f2a1268c0739103545537f89b9de0c92 (diff)
downloadffmpeg-a0e38aceba43526cd01d27e16e83d51f7518622a.tar.gz
avcodec/snowdec: Maintain avmv buffer
This avoids reallocating per frame Fixes: Assertion failure Fixes: 36359/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-6733238591684608 Fixes: 38623/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SNOW_fuzzer-6098656512573440 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 0faf04e807fc09bb3d72a034c284fe44b54fa76b) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/snow.h1
-rw-r--r--libavcodec/snowdec.c17
2 files changed, 14 insertions, 4 deletions
diff --git a/libavcodec/snow.h b/libavcodec/snow.h
index 41a3bef4de..d705188bfd 100644
--- a/libavcodec/snow.h
+++ b/libavcodec/snow.h
@@ -186,6 +186,7 @@ typedef struct SnowContext{
uint8_t *emu_edge_buffer;
AVMotionVector *avmv;
+ unsigned avmv_size;
int avmv_index;
uint64_t encoding_error[AV_NUM_DATA_POINTERS];
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 68afe0df26..177c2fa56d 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -493,9 +493,17 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
s->spatial_decomposition_count
);
- av_assert0(!s->avmv);
if (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS) {
- s->avmv = av_malloc_array(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2));
+ size_t size;
+ res = av_size_mult(s->b_width * s->b_height, sizeof(AVMotionVector) << (s->block_max_depth*2), &size);
+ if (res)
+ return res;
+ av_fast_malloc(&s->avmv, &s->avmv_size, size);
+ if (!s->avmv)
+ return AVERROR(ENOMEM);
+ } else {
+ s->avmv_size = 0;
+ av_freep(&s->avmv);
}
s->avmv_index = 0;
@@ -624,8 +632,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector));
}
- av_freep(&s->avmv);
-
if (res < 0)
return res;
@@ -645,6 +651,9 @@ static av_cold int decode_end(AVCodecContext *avctx)
ff_snow_common_end(s);
+ s->avmv_size = 0;
+ av_freep(&s->avmv);
+
return 0;
}