Bug 1592555 - Not allow adding a null receiver in the AudioMixer callback list. r=padenot

A null MixerCallbackReceiver in the AudioMixer callback list can create a crash when the AudioMixer::FinishMixing() is being called. Verify that the receiver is not null before adding it in the list.

Differential Revision: https://phabricator.services.mozilla.com/D51082

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2019-10-31 10:01:53 +00:00
parent 5ee706e95f
commit c0b57094e7
4 changed files with 15 additions and 13 deletions

View File

@ -34,7 +34,7 @@ AudioCaptureTrack::AudioCaptureTrack(TrackRate aRate)
mStarted(false) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(AudioCaptureTrack);
mMixer.AddCallback(this);
mMixer.AddCallback(WrapNotNull(this));
}
AudioCaptureTrack::~AudioCaptureTrack() {

View File

@ -7,10 +7,11 @@
#define MOZILLA_AUDIOMIXER_H_
#include "AudioSampleFormat.h"
#include "nsTArray.h"
#include "mozilla/PodOperations.h"
#include "mozilla/LinkedList.h"
#include "AudioStream.h"
#include "nsTArray.h"
#include "mozilla/LinkedList.h"
#include "mozilla/NotNull.h"
#include "mozilla/PodOperations.h"
namespace mozilla {
@ -54,6 +55,7 @@ class AudioMixer {
for (MixerCallback* cb = mCallbacks.getFirst(); cb != nullptr;
cb = cb->getNext()) {
MixerCallbackReceiver* receiver = cb->mReceiver;
MOZ_ASSERT(receiver);
receiver->MixerCallback(mMixedAudio.Elements(),
AudioSampleTypeToFormat<AudioDataValue>::Format,
mChannels, mFrames, mSampleRate);
@ -86,7 +88,7 @@ class AudioMixer {
}
}
void AddCallback(MixerCallbackReceiver* aReceiver) {
void AddCallback(NotNull<MixerCallbackReceiver*> aReceiver) {
mCallbacks.insertBack(new MixerCallback(aReceiver));
}
@ -122,9 +124,9 @@ class AudioMixer {
class MixerCallback : public LinkedListElement<MixerCallback> {
public:
explicit MixerCallback(MixerCallbackReceiver* aReceiver)
explicit MixerCallback(NotNull<MixerCallbackReceiver*> aReceiver)
: mReceiver(aReceiver) {}
MixerCallbackReceiver* mReceiver;
NotNull<MixerCallbackReceiver*> mReceiver;
};
/* Function that is called when the mixing is done. */

View File

@ -727,7 +727,7 @@ void AudioCallbackDriver::AddMixerCallback() {
MOZ_ASSERT(OnGraphThread());
if (!mAddedMixer) {
mGraphImpl->mMixer.AddCallback(this);
mGraphImpl->mMixer.AddCallback(WrapNotNull(this));
mAddedMixer = true;
}
}
@ -801,7 +801,7 @@ long AudioCallbackDriver::DataCallback(const AudioDataValue* aInputBuffer,
// Don't add the callback until we're inited and ready
if (!mAddedMixer) {
GraphImpl()->mMixer.AddCallback(this);
GraphImpl()->mMixer.AddCallback(WrapNotNull(this));
mAddedMixer = true;
}

View File

@ -86,7 +86,7 @@ TEST(AudioMixer, Test)
{
int iterations = 2;
mozilla::AudioMixer mixer;
mixer.AddCallback(&consumer);
mixer.AddCallback(WrapNotNull(&consumer));
fprintf(stderr, "Test AudioMixer constant buffer length.\n");
@ -99,7 +99,7 @@ TEST(AudioMixer, Test)
{
mozilla::AudioMixer mixer;
mixer.AddCallback(&consumer);
mixer.AddCallback(WrapNotNull(&consumer));
fprintf(stderr, "Test AudioMixer variable buffer length.\n");
@ -137,7 +137,7 @@ TEST(AudioMixer, Test)
{
mozilla::AudioMixer mixer;
mixer.AddCallback(&consumer);
mixer.AddCallback(WrapNotNull(&consumer));
fprintf(stderr, "Test AudioMixer variable channel count.\n");
@ -154,7 +154,7 @@ TEST(AudioMixer, Test)
{
mozilla::AudioMixer mixer;
mixer.AddCallback(&consumer);
mixer.AddCallback(WrapNotNull(&consumer));
fprintf(stderr, "Test AudioMixer variable stream count.\n");
mixer.Mix(a, 2, CHANNEL_LENGTH, AUDIO_RATE);