Bug 1181718 - Fallible allocation of blank audio data - r=jya

This is mostly to guard against allocating crazy amounts of memory due to
invalid data -- in this case a sample with an excessive number of frames.
This commit is contained in:
Gerald Squelart 2015-11-26 18:01:00 +01:00
Родитель 940e17e9c7
Коммит 83be56e479
1 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -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 "MediaDecoderReader.h"
#include "PlatformDecoderModule.h"
#include "nsRect.h"
#include "mozilla/RefPtr.h"
#include "mozilla/CheckedInt.h"
#include "VideoUtils.h"
#include "ImageContainer.h"
#include "MediaDecoderReader.h"
#include "MediaInfo.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/mozalloc.h" // for operator new, and new (fallible)
#include "mozilla/RefPtr.h"
#include "mozilla/TaskQueue.h"
#include "nsRect.h"
#include "PlatformDecoderModule.h"
#include "TimeUnits.h"
#include "VideoUtils.h"
namespace mozilla {
@ -58,6 +59,9 @@ public:
mCreator->Create(media::TimeUnit::FromMicroseconds(mSample->mTime),
media::TimeUnit::FromMicroseconds(mSample->mDuration),
mSample->mOffset);
if (!data) {
return NS_ERROR_OUT_OF_MEMORY;
}
mCallback->Output(data);
return NS_OK;
}
@ -183,7 +187,11 @@ public:
frames.value() > (UINT32_MAX / mChannelCount)) {
return nullptr;
}
auto samples = MakeUnique<AudioDataValue[]>(frames.value() * mChannelCount);
UniquePtr<AudioDataValue[]> samples(
new (fallible) AudioDataValue[frames.value() * mChannelCount]);
if (!samples) {
return nullptr;
}
// Fill the sound buffer with an A4 tone.
static const float pi = 3.14159265f;
static const float noteHz = 440.0f;