Bug 1530178 - copyFromChannel/copyToChannel until end of buffer when destination/source is longer r=padenot,karlt
authorValentin Millet <valentin.millet39@gmail.com>
Thu, 02 May 2019 09:24:57 +0000
changeset 531065 fe9afae0f868666eec95b151b50d5c6783c3cd91
parent 531064 0727a51d7ae175545ff5c772fc7547d4eff49404
child 531066 1c983b486cd0785a8d0a795b2fa845c72ca06add
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, karlt
bugs1530178
milestone68.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 1530178 - copyFromChannel/copyToChannel until end of buffer when destination/source is longer r=padenot,karlt than available space, as clarified in https://github.com/WebAudio/web-audio-api/issues/1004 Differential Revision: https://phabricator.services.mozilla.com/D25791
dom/media/webaudio/AudioBuffer.cpp
--- a/dom/media/webaudio/AudioBuffer.cpp
+++ b/dom/media/webaudio/AudioBuffer.cpp
@@ -298,20 +298,17 @@ bool AudioBuffer::RestoreJSChannelData(J
 }
 
 void AudioBuffer::CopyFromChannel(const Float32Array& aDestination,
                                   uint32_t aChannelNumber,
                                   uint32_t aStartInChannel, ErrorResult& aRv) {
   aDestination.ComputeLengthAndData();
 
   uint32_t length = aDestination.Length();
-  CheckedInt<uint32_t> end = aStartInChannel;
-  end += length;
-  if (aChannelNumber >= NumberOfChannels() || !end.isValid() ||
-      end.value() > Length()) {
+  if (aChannelNumber >= NumberOfChannels() || aStartInChannel > Length()) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   JS::AutoCheckCannotGC nogc;
   JSObject* channelArray = mJSChannels[aChannelNumber];
   if (channelArray) {
     if (JS_GetTypedArrayLength(channelArray) != Length()) {
@@ -321,17 +318,18 @@ void AudioBuffer::CopyFromChannel(const 
     }
 
     bool isShared = false;
     const float* sourceData =
         JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
     // The sourceData arrays should all have originated in
     // RestoreJSChannelData, where they are created unshared.
     MOZ_ASSERT(!isShared);
-    PodMove(aDestination.Data(), sourceData + aStartInChannel, length);
+    PodMove(aDestination.Data(), sourceData + aStartInChannel,
+            std::min(Length() - aStartInChannel, length));
     return;
   }
 
   if (!mSharedChannels.IsNull()) {
     CopyChannelDataToFloat(mSharedChannels, aChannelNumber, aStartInChannel,
                            aDestination.Data(), length);
     return;
   }
@@ -341,20 +339,17 @@ void AudioBuffer::CopyFromChannel(const 
 
 void AudioBuffer::CopyToChannel(JSContext* aJSContext,
                                 const Float32Array& aSource,
                                 uint32_t aChannelNumber,
                                 uint32_t aStartInChannel, ErrorResult& aRv) {
   aSource.ComputeLengthAndData();
 
   uint32_t length = aSource.Length();
-  CheckedInt<uint32_t> end = aStartInChannel;
-  end += length;
-  if (aChannelNumber >= NumberOfChannels() || !end.isValid() ||
-      end.value() > Length()) {
+  if (aChannelNumber >= NumberOfChannels() || aStartInChannel > Length()) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   if (!RestoreJSChannelData(aJSContext)) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return;
   }
@@ -367,17 +362,18 @@ void AudioBuffer::CopyToChannel(JSContex
     return;
   }
 
   bool isShared = false;
   float* channelData = JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
   // The channelData arrays should all have originated in
   // RestoreJSChannelData, where they are created unshared.
   MOZ_ASSERT(!isShared);
-  PodMove(channelData + aStartInChannel, aSource.Data(), length);
+  PodMove(channelData + aStartInChannel, aSource.Data(),
+          std::min(Length() - aStartInChannel, length));
 }
 
 void AudioBuffer::GetChannelData(JSContext* aJSContext, uint32_t aChannel,
                                  JS::MutableHandle<JSObject*> aRetval,
                                  ErrorResult& aRv) {
   if (aChannel >= NumberOfChannels()) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;