Bug 990868 - Limit ChannelMergerNode output channel count. r=padenot, a=lsblakk
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 20 May 2014 09:11:25 -0400
changeset 192310 20143f06748b
parent 192309 ece051d029de
child 192311 b01e7d87ef31
push id3566
push userryanvm@gmail.com
push date2014-05-20 13:28 +0000
treeherdermozilla-beta@7d6a74b90622 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, lsblakk
bugs990868
milestone30.0
Bug 990868 - Limit ChannelMergerNode output channel count. r=padenot, a=lsblakk
content/media/webaudio/ChannelMergerNode.cpp
--- a/content/media/webaudio/ChannelMergerNode.cpp
+++ b/content/media/webaudio/ChannelMergerNode.cpp
@@ -34,27 +34,32 @@ public:
     uint32_t channelCount = 0;
     for (uint16_t i = 0; i < InputCount(); ++i) {
       channelCount += aInput[i].mChannelData.Length();
     }
     if (channelCount == 0) {
       aOutput[0].SetNull(WEBAUDIO_BLOCK_SIZE);
       return;
     }
+    channelCount = std::min(channelCount, WebAudioUtils::MaxChannelCount);
     AllocateAudioBlock(channelCount, &aOutput[0]);
 
     // Append each channel in each input to the output
     uint32_t channelIndex = 0;
-    for (uint16_t i = 0; i < InputCount(); ++i) {
+    for (uint16_t i = 0; true; ++i) {
+      MOZ_ASSERT(i < InputCount());
       for (uint32_t j = 0; j < aInput[i].mChannelData.Length(); ++j) {
         AudioBlockCopyChannelWithScale(
             static_cast<const float*>(aInput[i].mChannelData[j]),
             aInput[i].mVolume,
             static_cast<float*>(const_cast<void*>(aOutput[0].mChannelData[channelIndex])));
         ++channelIndex;
+        if (channelIndex >= channelCount) {
+          return;
+        }
       }
     }
   }
 };
 
 ChannelMergerNode::ChannelMergerNode(AudioContext* aContext,
                                      uint16_t aInputCount)
   : AudioNode(aContext,