1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avutil/frame: Use av_memdup() for duplicating extended data array

Just do it like av_frame_replace().
Also "fixes" the swapped order or arguments to av_malloc_array()
(the first is supposed to be the number of elements, the second
the size of an element) and therefore part of ticket #11620.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-06-03 16:52:49 +02:00
parent abebdb1bdb
commit 2f5f2c013c

View File

@ -348,17 +348,16 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
if (src->extended_data != src->data) { if (src->extended_data != src->data) {
int ch = dst->ch_layout.nb_channels; int ch = dst->ch_layout.nb_channels;
if (!ch) { if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail; goto fail;
} }
dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch); dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
if (!dst->extended_data) { if (!dst->extended_data) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
} else } else
dst->extended_data = dst->data; dst->extended_data = dst->data;