Fixed NetEq overflow bug.

Negating an int can result in a value that cannot be represented as an int. This is fixed here by using a 64 bit variable.

BUG=chromium:663611

Review-Url: https://codereview.webrtc.org/2879863002
Cr-Commit-Position: refs/heads/master@{#18167}
This commit is contained in:
ivoc 2017-05-16 07:13:15 -07:00 committed by Commit bot
parent 52c83fe710
commit e3fc11464e

View File

@ -97,14 +97,17 @@ Operations DecisionLogicNormal::CngOperation(Modes prev_mode,
available_timestamp);
int32_t optimal_level_samp = static_cast<int32_t>(
(delay_manager_->TargetLevel() * packet_length_samples_) >> 8);
int32_t excess_waiting_time_samp = -timestamp_diff - optimal_level_samp;
const int64_t excess_waiting_time_samp =
-static_cast<int64_t>(timestamp_diff) - optimal_level_samp;
if (excess_waiting_time_samp > optimal_level_samp / 2) {
// The waiting time for this packet will be longer than 1.5
// times the wanted buffer delay. Apply fast-forward to cut the
// waiting time down to the optimal.
noise_fast_forward_ += excess_waiting_time_samp;
timestamp_diff += excess_waiting_time_samp;
noise_fast_forward_ = rtc::dchecked_cast<size_t>(noise_fast_forward_ +
excess_waiting_time_samp);
timestamp_diff =
rtc::saturated_cast<int32_t>(timestamp_diff + excess_waiting_time_samp);
}
if (timestamp_diff < 0 && prev_mode == kModeRfc3389Cng) {