coreaudio: obey MAX_CHANNELS when creating devices

fixes #57, which was caused by a buffer overflow with devices with more
than MAX_CHANNELS channels
This commit is contained in:
Michael Maltese 2016-04-25 15:16:12 -07:00
parent 2e064bfca8
commit 99f5b4e4b6

View file

@ -280,7 +280,10 @@ static int from_coreaudio_layout(const AudioChannelLayout *ca_layout, struct Sou
switch (ca_layout->mChannelLayoutTag) { switch (ca_layout->mChannelLayoutTag) {
case kAudioChannelLayoutTag_UseChannelDescriptions: 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) { for (int i = 0; i < layout->channel_count; i += 1) {
layout->channels[i] = from_channel_descr(&ca_layout->mChannelDescriptions[i]); layout->channels[i] = from_channel_descr(&ca_layout->mChannelDescriptions[i]);
} }