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 199238 1e0fc97c0b28032ebd0ead475e9ec8f19e3b400c
parent 199237 1be457e6d85b09b9a4dcc0d1beb137a63dc3fd65
child 199239 e15889058541cdb005c4de0d9024364c8550e0b2
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, lsblakk
bugs990868
milestone31.0a2
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;
+        }
       }
     }
   }
 
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
   {
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }