Skip to content

Commit a69a50f

Browse files
committed
Add additional validation checks around SoundEmjiSynthesizer, and guarantee mutual exclusion when IRQ triggers
1 parent d3d9fd5 commit a69a50f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

source/SoundEmojiSynthesizer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,24 @@ int SoundEmojiSynthesizer::play(ManagedBuffer sound)
109109
MicroBitAudio::requestActivation();
110110

111111
// Validate inputs
112-
if (sound.length() < (int) sizeof(SoundEffect))
112+
SoundEffect *fx = (SoundEffect *) &sound[0];
113+
if (sound.length() < (int) sizeof(SoundEffect) || fx->frequency < 0)
113114
return DEVICE_INVALID_PARAMETER;
114115

115116
// If a playout is already in progress, block until it has been scheduled.
116117
lock.wait();
117118

119+
target_disable_irq();
120+
118121
// Store the requested sequence of sound effects.
119122
effectBuffer = sound;
120123

121124
// Scheduled this sound effect for playout.
122125
// Generation will start the next time a pull() operation is called from downstream.
123126
nextSoundEffect();
124127

128+
target_enable_irq();
129+
125130
// Perform on demand activiation if this is the first time this compoennt has been used.
126131
// Simply issue a pull request to start the process.
127132
if (!(status & EMOJI_SYNTHESIZER_STATUS_ACTIVE))

0 commit comments

Comments
 (0)