Bug 1414632 - Prevent division by zero in webrtc::Merge::SignalScaling; r=jesup
authorDan Minor <dminor@mozilla.com>
Wed, 08 Nov 2017 12:39:53 -0500
changeset 444284 e47ee65540ba07f65f194908157834edd41a2272
parent 444283 7d9324e2ab34946539be9f17d74f639aae5ba7e5
child 444285 dbdadf5e2691bb6a159ffcefae97221110d3d533
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1414632
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1414632 - Prevent division by zero in webrtc::Merge::SignalScaling; r=jesup A zero input_length here would be caused by a decoder error in NetEqImpl::Decode(). Looking at the code in GetAudioInternal() which calls Decode() it appears that the intention is to continue processing even if no new audio data is decoded. Based on this, it seems safest to just skip muting in SignalScaling if the input_length is zero. The other potential cause of a division by zero here is if fs_mult_ is zero which should not normally happen. But there's no harm in checking for that as well. MozReview-Commit-ID: J0pd2wbjeZl
media/webrtc/trunk/webrtc/modules/audio_coding/neteq/merge.cc
--- a/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/merge.cc
+++ b/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/merge.cc
@@ -206,16 +206,22 @@ size_t Merge::GetExpandedSignal(size_t* 
   return required_length;
 }
 
 int16_t Merge::SignalScaling(const int16_t* input, size_t input_length,
                              const int16_t* expanded_signal) const {
   // Adjust muting factor if new vector is more or less of the BGN energy.
   const size_t mod_input_length =
       std::min(static_cast<size_t>(64 * fs_mult_), input_length);
+
+  // Missing input, do no muting
+  if (mod_input_length == 0) {
+    return 16384;
+  }
+
   const int16_t expanded_max =
       WebRtcSpl_MaxAbsValueW16(expanded_signal, mod_input_length);
   int32_t factor = (expanded_max * expanded_max) /
       (std::numeric_limits<int32_t>::max() /
           static_cast<int32_t>(mod_input_length));
   const int expanded_shift = factor == 0 ? 0 : 31 - WebRtcSpl_NormW32(factor);
   int32_t energy_expanded = WebRtcSpl_DotProductWithScale(expanded_signal,
                                                           expanded_signal,