[x264-devel] Fix crash with --fps 0
Anton Mitrofanov
git at videolan.org
Tue Jul 17 21:21:41 CEST 2012
x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Fri Jun 22 22:02:24 2012 +0400| [37be55213a39db40cf159ada319bd482a1b00680] | committer: Jason Garrett-Glaser
Fix crash with --fps 0
Fix some integer overflows and check input parameters better.
Also fix incorrect type specifiers for demuxer info printing.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=37be55213a39db40cf159ada319bd482a1b00680
---
common/common.c | 12 ++++++++++--
encoder/encoder.c | 12 +++++++++++-
encoder/set.c | 2 +-
output/mp4.c | 4 ++--
x264.c | 2 +-
5 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/common/common.c b/common/common.c
index 3f40e66..59c2f05 100644
--- a/common/common.c
+++ b/common/common.c
@@ -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")
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 104df1a..cdff8ec 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -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 );
diff --git a/encoder/set.c b/encoder/set.c
index d384dd4..531bca0 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -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 );
diff --git a/output/mp4.c b/output/mp4.c
index 7f12365..188561d 100644
--- a/output/mp4.c
+++ b/output/mp4.c
@@ -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 5519810..8dcc655 100644
--- 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' );
More information about the x264-devel
mailing list