[FFmpeg-devel] [PATCH 2/3] avutil/mastering_display_metadata: set a sane default value for AVRational fields
James Almer
jamrial at gmail.com
Tue Jun 18 22:20:33 EEST 2024
Prevent potential divisions by 0 when using them immediately after allocation.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavutil/mastering_display_metadata.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
index ea41f13f9d..73a36c661e 100644
--- a/libavutil/mastering_display_metadata.c
+++ b/libavutil/mastering_display_metadata.c
@@ -25,9 +25,15 @@
#include "mastering_display_metadata.h"
#include "mem.h"
-AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void)
+static void get_defaults(AVMasteringDisplayMetadata *mastering)
{
- return av_mallocz(sizeof(AVMasteringDisplayMetadata));
+ for (int i = 0; i < 3; i++)
+ for (int j = 0; j < 2; j++)
+ mastering->display_primaries[i][j] = (AVRational) { 0, 1 };
+ mastering->white_point[0] =
+ mastering->white_point[1] =
+ mastering->min_luminance =
+ mastering->max_luminance = (AVRational) { 0, 1 };
}
AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *size)
@@ -36,12 +42,19 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *siz
if (!mastering)
return NULL;
+ get_defaults(mastering);
+
if (size)
*size = sizeof(*mastering);
return mastering;
}
+AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void)
+{
+ return av_mastering_display_metadata_alloc_size(NULL);
+}
+
AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame)
{
AVFrameSideData *side_data = av_frame_new_side_data(frame,
@@ -51,6 +64,7 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFra
return NULL;
memset(side_data->data, 0, sizeof(AVMasteringDisplayMetadata));
+ get_defaults((AVMasteringDisplayMetadata *)side_data->data);
return (AVMasteringDisplayMetadata *)side_data->data;
}
--
2.45.2
More information about the ffmpeg-devel
mailing list