diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-09-06 22:32:22 -0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-09-06 22:32:22 -0400 |
commit | f4f5a6a099540c9a8fea100e3c1aeab2e63d3245 (patch) | |
tree | 52be2f81195d972916a0760b7ba61ab2be1c624f /src | |
parent | 691d49355f83a220d35f129f12471c8ab5a62084 (diff) | |
download | opus-f4f5a6a099540c9a8fea100e3c1aeab2e63d3245.tar.gz |
Prevents an overflow in multi-stream encoder rate computation
Also avoids stupidly high/low rates
Diffstat (limited to 'src')
-rw-r--r-- | src/opus_multistream_encoder.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c index b9d60c88..30cafe11 100644 --- a/src/opus_multistream_encoder.c +++ b/src/opus_multistream_encoder.c @@ -705,7 +705,7 @@ static void surround_rate_allocation( total = (nb_uncoupled<<8) /* mono */ + coupled_ratio*nb_coupled /* stereo */ + nb_lfe*lfe_ratio; - channel_rate = 256*(st->bitrate_bps-lfe_offset*nb_lfe-stream_offset*(nb_coupled+nb_uncoupled))/total; + channel_rate = 256*(opus_int64)(st->bitrate_bps-lfe_offset*nb_lfe-stream_offset*(nb_coupled+nb_uncoupled))/total; } #ifndef FIXED_POINT if (st->variable_duration==OPUS_FRAMESIZE_VARIABLE && frame_size != Fs/50) @@ -1159,9 +1159,11 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) case OPUS_SET_BITRATE_REQUEST: { opus_int32 value = va_arg(ap, opus_int32); - if (value<0 && value!=OPUS_AUTO && value!=OPUS_BITRATE_MAX) + if (value != OPUS_AUTO && value != OPUS_BITRATE_MAX) { - goto bad_arg; + if (value <= 0) + goto bad_arg; + value = IMIN(300000*st->layout.nb_channels, IMAX(500*st->layout.nb_channels, value)); } st->bitrate_bps = value; } |