miniaudio
miniaudio copied to clipboard
Multiple stack overflows on coreaudio with soundcards with large amount of channels
We're starting to see a few high-channel-count (1024+ like the Marian Clara E) soundcards ; this seems to cause issue with the coreaudio backend for instance starting from 128 channels.
- Code seems incorrect in ma_log_postv: the va_list needs to be reinitialized after the first vsnprintf call if we fall into the overflow case ; see https://stackoverflow.com/a/55274741/1495627 or https://stackoverflow.com/questions/23157530/vsnprintf-on-mac-gives-exc-bad-access
So the whole logic of ma_log_postf wrapping ma_log_postv doesn't really make sense as in the end you have to call va_start / va_end from within postv anyways
- Code is also incorrect in
ma_channel_map_to_stringas it does not null-terminate pBufferOuut if we overflow the buffer size.
I'll prepare a PR to fix both of these and likely report soon the usage of these high-channel-count cards with other backends :)
Thanks. I haven't done any testing personally on huge channel counts so I'd be happy to hear any feedback on that.
A heads up in case you aren't already aware, I have a macro called MA_MAX_CHANNELS which is defined as 254 so I wouldn't be surprised if some functionality might be outright broken beyond that point. I think channel maps and the node graph stuff in particular would be an issue.
thanks! will report as soon as I can test. So far up to 256 channels seem to work.
I had a look at your PR, but I didn't like your proposed solutions.
For the logging thing, I think the error was that I was not calling va_copy(). I want to keep the current pattern where the "f" version calls into the "v" version.
For the channel map thing, your proposal returns 0 when pBufferOut is null which is incorrect. The intended usage of that function is to call it with pBufferOut as null to compute the required length. Similar in concept to snprintf().
I haven't had a chance to properly test these so I'll leave this ticket open as a reminder for myself to get to that. Changes are in the dev branch if you wanted to try them out for yourself.
These changes seem to be working fine for me. Closing.