Bug 880129 - Correctly handle AnalyserNodes with a buffer size smaller than 128; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 07 Jun 2013 07:33:00 -0400
changeset 145848 728ac315adcb9fe6cb6070e1f796952f10605429
parent 145847 cebcec9ca3c3dbd57fe037e1564b2218139d12e3
child 145849 aa9a38e68dcfe5b66eede1654d01334b2d242b45
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs880129
milestone24.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 880129 - Correctly handle AnalyserNodes with a buffer size smaller than 128; r=roc
content/media/test/crashtests/880129.html
content/media/test/crashtests/crashtests.list
content/media/webaudio/AnalyserNode.cpp
new file mode 100644
--- /dev/null
+++ b/content/media/test/crashtests/880129.html
@@ -0,0 +1,9 @@
+<script>
+try { o1 = new window.AudioContext(3, 2, 44100); } catch(e) { }
+try { o6 = o1.createBufferSource(); } catch(e) { }
+try { o15 = o1.createAnalyser(); } catch(e) { }
+try { o15.fftSize = 32; } catch(e) { }
+try { o6.connect(o15,0,0) } catch(e) { }
+try { o27 = o1.createPanner(); } catch(e) { }
+try { o6.buffer = function(){var buffer = o1.createBuffer(2, 1148, o1.sampleRate);for(var c=0; c<2; c++) {for(var i=0; i<1148; i++) {buffer.getChannelData(c)[i] = 0;}}return buffer;}() } catch(e) { }
+</script>
\ No newline at end of file
--- a/content/media/test/crashtests/crashtests.list
+++ b/content/media/test/crashtests/crashtests.list
@@ -33,9 +33,10 @@ load 876249.html
 load 876252.html
 load 876834.html
 load 877820.html
 load 878014.html
 load 878328.html
 load 878407.html
 load 878478.html
 load 877527.html
+load 880129.html
 skip-if(B2G) load 880202.html # load failed, bug 833371 for B2G
--- a/content/media/webaudio/AnalyserNode.cpp
+++ b/content/media/webaudio/AnalyserNode.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/AnalyserNode.h"
 #include "mozilla/dom/AnalyserNodeBinding.h"
 #include "AudioNodeEngine.h"
 #include "AudioNodeStream.h"
 #include "mozilla/Mutex.h"
+#include "mozilla/PodOperations.h"
 #include "kiss_fft/kiss_fftr.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_ISUPPORTS_INHERITED0(AnalyserNode, AudioNode)
 
 class AnalyserNodeEngine : public AudioNodeEngine
@@ -270,31 +271,36 @@ AnalyserNode::AllocateBuffer()
   return result;
 }
 
 void
 AnalyserNode::AppendChunk(const AudioChunk& aChunk)
 {
   const uint32_t bufferSize = mBuffer.Length();
   const uint32_t channelCount = aChunk.mChannelData.Length();
-  const uint32_t chunkCount = aChunk.mDuration;
+  uint32_t chunkDuration = aChunk.mDuration;
   MOZ_ASSERT((bufferSize & (bufferSize - 1)) == 0); // Must be a power of two!
   MOZ_ASSERT(channelCount > 0);
-  MOZ_ASSERT(chunkCount == WEBAUDIO_BLOCK_SIZE);
+  MOZ_ASSERT(chunkDuration == WEBAUDIO_BLOCK_SIZE);
 
-  memcpy(mBuffer.Elements() + mWriteIndex, aChunk.mChannelData[0], sizeof(float) * chunkCount);
+  if (chunkDuration > bufferSize) {
+    // Copy a maximum bufferSize samples.
+    chunkDuration = bufferSize;
+  }
+
+  PodCopy(mBuffer.Elements() + mWriteIndex, static_cast<const float*>(aChunk.mChannelData[0]), chunkDuration);
   for (uint32_t i = 1; i < channelCount; ++i) {
     AudioBlockAddChannelWithScale(static_cast<const float*>(aChunk.mChannelData[i]), 1.0f,
                                   mBuffer.Elements() + mWriteIndex);
   }
   if (channelCount > 1) {
     AudioBlockInPlaceScale(mBuffer.Elements() + mWriteIndex, 1,
                            1.0f / aChunk.mChannelData.Length());
   }
-  mWriteIndex += chunkCount;
+  mWriteIndex += chunkDuration;
   MOZ_ASSERT(mWriteIndex <= bufferSize);
   if (mWriteIndex >= bufferSize) {
     mWriteIndex = 0;
   }
 }
 
 }
 }