[FFmpeg-devel] [PATCH 3/3] avutil/stereo3d: set a sane default value for AVRational fields

James Almer jamrial at gmail.com
Tue Jun 18 22:20:34 EEST 2024


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

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavutil/stereo3d.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c
index a40a9439bb..19e81e4124 100644
--- a/libavutil/stereo3d.c
+++ b/libavutil/stereo3d.c
@@ -26,9 +26,20 @@
 #include "mem.h"
 #include "stereo3d.h"
 
+static void get_defaults(AVStereo3D *stereo)
+{
+    stereo->horizontal_disparity_adjustment = (AVRational) { 0, 1 };
+}
+
 AVStereo3D *av_stereo3d_alloc(void)
 {
-    return av_mallocz(sizeof(AVStereo3D));
+    AVStereo3D *stereo = av_mallocz(sizeof(AVStereo3D));
+    if (!stereo)
+        return NULL;
+
+    get_defaults(stereo);
+
+    return stereo;
 }
 
 AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame)
@@ -40,6 +51,7 @@ AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame)
         return NULL;
 
     memset(side_data->data, 0, sizeof(AVStereo3D));
+    get_defaults((AVStereo3D *)side_data->data);
 
     return (AVStereo3D *)side_data->data;
 }
-- 
2.45.2



More information about the ffmpeg-devel mailing list