From 33012b4141fda7aaa35ba3eee32f31265ed837cc Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 8 Nov 2016 17:46:42 +0100 Subject: ao_alsa: fill unused ALSA channels with silence This happens when ALSA gives us more channels than we asked for, for whatever reasons. It looks like this wasn't handled correctly. The mpv and ALSA channel counts could mismatch, which would lead to UB. I couldn't actually trigger this case, though. I'm fairly sure that drivers or plugins exist that do it anyway. (Inofficial ALSA motto: if it can be broken, then why not break it?) --- audio/out/ao_alsa.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'audio') diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index f80a46a5cc..f30417ff68 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -794,8 +794,13 @@ static int init_device(struct ao *ao, int mode) if (num_channels != ao->channels.num) { int req = ao->channels.num; mp_chmap_from_channels(&ao->channels, MPMIN(2, num_channels)); + mp_chmap_fill_na(&ao->channels, num_channels); MP_ERR(ao, "Asked for %d channels, got %d - fallback to %s.\n", req, num_channels, mp_chmap_to_str(&ao->channels)); + if (num_channels != ao->channels.num) { + MP_FATAL(ao, "mismatching channel counts.\n"); + goto alsa_error; + } } err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &p->buffersize); -- cgit v1.2.3