]> git.sesse.net Git - x264/commitdiff
Fix crash with --fps 0
authorAnton Mitrofanov <BugMaster@narod.ru>
Fri, 22 Jun 2012 18:02:24 +0000 (22:02 +0400)
committerFiona Glaser <fiona@x264.com>
Tue, 3 Jul 2012 20:10:02 +0000 (13:10 -0700)
Fix some integer overflows and check input parameters better.
Also fix incorrect type specifiers for demuxer info printing.

common/common.c
encoder/encoder.c
encoder/set.c
output/mp4.c
x264.c

index 3f40e66f11c205259ed9cc9226960bcb404043fb..59c2f05188c75870610ae1f1c9857d6014382ead 100644 (file)
@@ -693,8 +693,16 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         else
         {
             float fps = atof(value);
-            p->i_fps_num = (int)(fps * 1000 + .5);
-            p->i_fps_den = 1000;
+            if( fps > 0 && fps <= INT_MAX/1000 )
+            {
+                p->i_fps_num = (int)(fps * 1000 + .5);
+                p->i_fps_den = 1000;
+            }
+            else
+            {
+                p->i_fps_num = atoi(value);
+                p->i_fps_den = 1;
+            }
         }
     }
     OPT2("ref", "frameref")
index f6246f91c5f0efdf286d6b1594d3337bb89072e6..3b31f0108e8229db5eaa09d9f191bbd6a4c0d7cd 100644 (file)
@@ -613,6 +613,11 @@ static int x264_validate_parameters( x264_t *h, int b_open )
     h->param.rc.i_qp_min = x264_clip3( h->param.rc.i_qp_min, 0, h->param.rc.i_qp_max );
     h->param.rc.i_qp_step = x264_clip3( h->param.rc.i_qp_step, 2, QP_MAX );
     h->param.rc.i_bitrate = x264_clip3( h->param.rc.i_bitrate, 0, 2000000 );
+    if( h->param.rc.i_rc_method == X264_RC_ABR && !h->param.rc.i_bitrate )
+    {
+        x264_log( h, X264_LOG_ERROR, "bitrate not specified\n" );
+        return -1;
+    }
     h->param.rc.i_vbv_buffer_size = x264_clip3( h->param.rc.i_vbv_buffer_size, 0, 2000000 );
     h->param.rc.i_vbv_max_bitrate = x264_clip3( h->param.rc.i_vbv_max_bitrate, 0, 2000000 );
     h->param.rc.f_vbv_buffer_init = x264_clip3f( h->param.rc.f_vbv_buffer_init, 0, 2000000 );
@@ -721,7 +726,12 @@ static int x264_validate_parameters( x264_t *h, int b_open )
         x264_log( h, X264_LOG_WARNING, "intra-refresh is not compatible with open-gop\n" );
         h->param.b_open_gop = 0;
     }
-    float fps = h->param.i_fps_num > 0 && h->param.i_fps_den > 0 ? (float) h->param.i_fps_num / h->param.i_fps_den : 25.0;
+    if( !h->param.i_fps_num || !h->param.i_fps_den )
+    {
+        h->param.i_fps_num = 25;
+        h->param.i_fps_den = 1;
+    }
+    float fps = (float) h->param.i_fps_num / h->param.i_fps_den;
     if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO )
         h->param.i_keyint_min = X264_MIN( h->param.i_keyint_max / 10, fps );
     h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );
index d384dd46a27af44c6b2a3d58016e5acadeeb4425..531bca0c2d57d969221971d3587b67c7f6f22515 100644 (file)
@@ -778,7 +778,7 @@ int x264_validate_levels( x264_t *h, int verbose )
 
 #define CHECK( name, limit, val ) \
     if( (val) > (limit) ) \
-        ERROR( name " (%d) > level limit (%d)\n", (int)(val), (limit) );
+        ERROR( name " (%"PRId64") > level limit (%d)\n", (int64_t)(val), (limit) );
 
     CHECK( "VBV bitrate", (l->bitrate * cbp_factor) / 4, h->param.rc.i_vbv_max_bitrate );
     CHECK( "VBV buffer", (l->cpb * cbp_factor) / 4, h->param.rc.i_vbv_buffer_size );
index 7f123657de16dc93c65b68c21141cd9a15b2a7da..188561d220d1cb21a323ff7f93114dbea3332f69 100644 (file)
@@ -207,8 +207,8 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
     p_mp4->i_delay_frames = p_param->i_bframe ? (p_param->i_bframe_pyramid ? 2 : 1) : 0;
     p_mp4->i_dts_compress_multiplier = p_mp4->b_dts_compress * p_mp4->i_delay_frames + 1;
 
-    p_mp4->i_time_res = p_param->i_timebase_den * p_mp4->i_dts_compress_multiplier;
-    p_mp4->i_time_inc = p_param->i_timebase_num * p_mp4->i_dts_compress_multiplier;
+    p_mp4->i_time_res = (uint64_t)p_param->i_timebase_den * p_mp4->i_dts_compress_multiplier;
+    p_mp4->i_time_inc = (uint64_t)p_param->i_timebase_num * p_mp4->i_dts_compress_multiplier;
     FAIL_IF_ERR( p_mp4->i_time_res > UINT32_MAX, "mp4", "MP4 media timescale %"PRIu64" exceeds maximum\n", p_mp4->i_time_res )
 
     p_mp4->i_track = gf_isom_new_track( p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
diff --git a/x264.c b/x264.c
index b2b796673c05baaf9e43bec0f78ea90f565f9eee..901e947da8758dd619e7467b97db0a70dd9ac055 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -1499,7 +1499,7 @@ generic_option:
 
     x264_reduce_fraction( &info.sar_width, &info.sar_height );
     x264_reduce_fraction( &info.fps_num, &info.fps_den );
-    x264_cli_log( demuxername, X264_LOG_INFO, "%dx%d%c %d:%d @ %d/%d fps (%cfr)\n", info.width,
+    x264_cli_log( demuxername, X264_LOG_INFO, "%dx%d%c %u:%u @ %u/%u fps (%cfr)\n", info.width,
                   info.height, info.interlaced ? 'i' : 'p', info.sar_width, info.sar_height,
                   info.fps_num, info.fps_den, info.vfr ? 'v' : 'c' );