[x264-devel] Fix possible division by zero in mkv and flv muxers on close

Anton Mitrofanov git at videolan.org
Mon Feb 7 06:31:29 CET 2011


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Tue Feb  1 00:43:03 2011 +0300| [7231bdcd2cfdb5d625141ae81ebbdd964b146135] | committer: Jason Garrett-Glaser

Fix possible division by zero in mkv and flv muxers on close
This could crash if anything failed before output.set_param (for example, incorrect params refused by x264_encoder_open).
Bug introduced in r1873.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=7231bdcd2cfdb5d625141ae81ebbdd964b146135
---

 output/flv.c      |    2 +-
 output/matroska.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/output/flv.c b/output/flv.c
index abda3bd..87335b8 100644
--- a/output/flv.c
+++ b/output/flv.c
@@ -310,7 +310,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
 
     double total_duration = (2 * largest_pts - second_largest_pts) * p_flv->d_timebase;
 
-    if( x264_is_regular_file( c->fp ) )
+    if( x264_is_regular_file( c->fp ) && total_duration > 0 )
     {
         double framerate;
         uint64_t filesize = ftell( c->fp );
diff --git a/output/matroska.c b/output/matroska.c
index f31a6a5..0d8666c 100644
--- a/output/matroska.c
+++ b/output/matroska.c
@@ -202,7 +202,7 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
     int ret;
     int64_t i_last_delta;
 
-    i_last_delta = (int64_t)(((largest_pts - second_largest_pts) * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5);
+    i_last_delta = p_mkv->i_timebase_den ? (int64_t)(((largest_pts - second_largest_pts) * p_mkv->i_timebase_num / p_mkv->i_timebase_den) + 0.5) : 0;
 
     ret = mk_close( p_mkv->w, i_last_delta );
 



More information about the x264-devel mailing list