From 99f5b4e4b64adcfa4960e484845585308ceb4110 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Mon, 25 Apr 2016 15:16:12 -0700 Subject: [PATCH] coreaudio: obey MAX_CHANNELS when creating devices fixes #57, which was caused by a buffer overflow with devices with more than MAX_CHANNELS channels --- src/coreaudio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coreaudio.c b/src/coreaudio.c index 7c96121..58ab69e 100644 --- a/src/coreaudio.c +++ b/src/coreaudio.c @@ -280,7 +280,10 @@ static int from_coreaudio_layout(const AudioChannelLayout *ca_layout, struct Sou switch (ca_layout->mChannelLayoutTag) { case kAudioChannelLayoutTag_UseChannelDescriptions: { - layout->channel_count = ca_layout->mNumberChannelDescriptions; + layout->channel_count = soundio_int_min( + SOUNDIO_MAX_CHANNELS, + ca_layout->mNumberChannelDescriptions + ); for (int i = 0; i < layout->channel_count; i += 1) { layout->channels[i] = from_channel_descr(&ca_layout->mChannelDescriptions[i]); }