[FFmpeg-cvslog] avutil/mastering_display_metadata: set a sane default value for AVRational fields

James Almer git at videolan.org
Thu Jun 20 23:17:13 EEST 2024


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Jun 18 16:12:23 2024 -0300| [1044c09ecae478fea33f80c13f94c7381a8f0a24] | committer: James Almer

avutil/mastering_display_metadata: set a sane default value for AVRational fields

Prevent potential divisions by 0 when using them immediately after allocation.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1044c09ecae478fea33f80c13f94c7381a8f0a24
---

 libavutil/mastering_display_metadata.c | 16 +++++++++++++++-
 libavutil/version.h                    |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
index ea41f13f9d..dd37ed7d0e 100644
--- a/libavutil/mastering_display_metadata.c
+++ b/libavutil/mastering_display_metadata.c
@@ -25,9 +25,20 @@
 #include "mastering_display_metadata.h"
 #include "mem.h"
 
+static void get_defaults(AVMasteringDisplayMetadata *mastering)
+{
+    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(void)
 {
-    return av_mallocz(sizeof(AVMasteringDisplayMetadata));
+    return av_mastering_display_metadata_alloc_size(NULL);
 }
 
 AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *size)
@@ -36,6 +47,8 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *siz
     if (!mastering)
         return NULL;
 
+    get_defaults(mastering);
+
     if (size)
         *size = sizeof(*mastering);
 
@@ -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;
 }
diff --git a/libavutil/version.h b/libavutil/version.h
index 4f51d441fa..9c24b64032 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -80,7 +80,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  59
 #define LIBAVUTIL_VERSION_MINOR  24
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MICRO 102
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list