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 216873 82f4086ba2c7
parent 216872 d41af0c7fdaf
child 216874 b6985e15046b
push id3949
push userryanvm@gmail.com
push date2014-09-29 16:30 +0000
treeherdermozilla-beta@82f4086ba2c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, sledru
bugs1033066
milestone33.0
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
@@ -150,17 +150,18 @@ void
 AudioSegment::WriteTo(uint64_t aID, AudioStream* aOutput, AudioMixer* aMixer)
 {
   uint32_t outputChannels = aOutput->GetChannels();
   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() * outputChannels;
   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;