[vlc-commits] demux: mp4: fix divbyzero (fix #17984)

Francois Cartegnie git at videolan.org
Tue Feb 7 16:41:43 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Feb  7 16:40:26 2017 +0100| [548dde56c85f2e4aa4ab7e6d5ff02c10723096b3] | committer: Francois Cartegnie

demux: mp4: fix divbyzero (fix #17984)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=548dde56c85f2e4aa4ab7e6d5ff02c10723096b3
---

 modules/demux/mp4/libmp4.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 0edf687..ebf3627 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1104,7 +1104,7 @@ static int MP4_ReadBox_tkhd(  stream_t *p_stream, MP4_Box_t *p_box )
     MP4_GET4BYTES( p_box->data.p_tkhd->i_width );
     MP4_GET4BYTES( p_box->data.p_tkhd->i_height );
 
-    double rotation;    //angle in degrees to be rotated clockwise
+    double rotation = 0;//angle in degrees to be rotated clockwise
     double scale[2];    // scale factor; sx = scale[0] , sy = scale[1]
     int32_t *matrix = p_box->data.p_tkhd->i_matrix;
 
@@ -1113,10 +1113,13 @@ static int MP4_ReadBox_tkhd(  stream_t *p_stream, MP4_Box_t *p_box )
     scale[1] = sqrt(conv_fx(matrix[1]) * conv_fx(matrix[1]) +
                     conv_fx(matrix[4]) * conv_fx(matrix[4]));
 
-    rotation = atan2(conv_fx(matrix[1]) / scale[1], conv_fx(matrix[0]) / scale[0]) * 180 / M_PI;
-
-    if (rotation < 0)
-        rotation += 360.;
+    if( likely(scale[0] > 0 && scale[1] > 0) )
+    {
+        rotation = atan2(conv_fx(matrix[1]) / scale[1],
+                         conv_fx(matrix[0]) / scale[0]) * 180 / M_PI;
+        if (rotation < 0)
+            rotation += 360.;
+    }
 
     p_box->data.p_tkhd->f_rotation = rotation;
 



More information about the vlc-commits mailing list