Bug 1033066 - Never let AudioSegments underflow mDuration and cause OOM allocation. r=karlt, a=sledru
authorRandell Jesup <rjesup@jesup.org>
Fri, 26 Sep 2014 14:13:17 -0400
changeset 217864 f764e665b39c8846ef712d043ddcb2881dc4fb24
parent 217863 4a2494b6356128f7ff3e8c82d8f08047d163632e
child 217865 3ad931b42b9db42b3e77c19e82321ee0baa85b53
push id6968
push userryanvm@gmail.com
push dateMon, 29 Sep 2014 16:41:41 +0000
treeherdermozilla-aurora@9cfcdef0dc56 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, sledru
bugs1033066
milestone34.0a2
Bug 1033066 - Never let AudioSegments underflow mDuration and cause OOM allocation. r=karlt, a=sledru
content/media/AudioSegment.cpp
content/media/AudioSegment.h
--- a/content/media/AudioSegment.cpp
+++ b/content/media/AudioSegment.cpp
@@ -149,17 +149,18 @@ void AudioSegment::ResampleChunks(SpeexR
 void
 AudioSegment::WriteTo(uint64_t aID, AudioMixer& aMixer, uint32_t aOutputChannels, uint32_t aSampleRate)
 {
   nsAutoTArray<AudioDataValue,AUDIO_PROCESSING_FRAMES*GUESS_AUDIO_CHANNELS> buf;
   nsAutoTArray<const void*,GUESS_AUDIO_CHANNELS> channelData;
   // Offset in the buffer that will end up sent to the AudioStream, in samples.
   uint32_t offset = 0;
 
-  if (!GetDuration()) {
+  if (GetDuration() <= 0) {
+    MOZ_ASSERT(GetDuration() == 0);
     return;
   }
 
   uint32_t outBufferLength = GetDuration() * aOutputChannels;
   buf.SetLength(outBufferLength);
 
 
   for (ChunkIterator ci(*this); !ci.IsEnded(); ci.Next()) {
--- a/content/media/AudioSegment.h
+++ b/content/media/AudioSegment.h
@@ -81,18 +81,18 @@ void DownmixAndInterleave(const nsTArray
  * separate pointers to each channel's buffer.
  */
 struct AudioChunk {
   typedef mozilla::AudioSampleFormat SampleFormat;
 
   // Generic methods
   void SliceTo(TrackTicks aStart, TrackTicks aEnd)
   {
-    NS_ASSERTION(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
-                 "Slice out of bounds");
+    MOZ_ASSERT(aStart >= 0 && aStart < aEnd && aEnd <= mDuration,
+               "Slice out of bounds");
     if (mBuffer) {
       MOZ_ASSERT(aStart < INT32_MAX, "Can't slice beyond 32-bit sample lengths");
       for (uint32_t channel = 0; channel < mChannelData.Length(); ++channel) {
         mChannelData[channel] = AddAudioSampleOffset(mChannelData[channel],
             mBufferFormat, int32_t(aStart));
       }
     }
     mDuration = aEnd - aStart;