Commit 5e3aaf1a authored by Anton Mitrofanov's avatar Anton Mitrofanov Committed by Fiona Glaser

Fix crash with --fps 0

Fix some integer overflows and check input parameters better.
Also fix incorrect type specifiers for demuxer info printing.
parent df700eae
......@@ -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")
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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,
......
......@@ -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' );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment