From: Jaroslav Kysela Date: Mon, 30 Nov 2026 13:34:52 +0000 (+0100) Subject: pcm: multi: guard chmap handlers against unmapped channels X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=36c34b261b80be2d97bc885fe8ad3894abd22337;p=alsa-lib.git pcm: multi: guard chmap handlers against unmapped channels snd_pcm_multi_query_chmaps(), snd_pcm_multi_get_chmap() and snd_pcm_multi_set_chmap() index multi->slaves[] / slave_maps[] with bind->slave_idx without checking for the slave_idx < 0 sentinel used for unmapped channels in sparse binding maps. For such channels this reads or writes array index -1 (out of bounds). Skip unmapped channels: report SND_CHMAP_UNKNOWN for the query/get paths and leave them untouched on set. This matches the existing slave_idx < 0 handling elsewhere in the plugin (channel info, mmap commit, dump). Signed-off-by: Jaroslav Kysela --- diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 9274a636..00580538 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -877,10 +877,16 @@ static snd_pcm_chmap_query_t **snd_pcm_multi_query_chmaps(snd_pcm_t *pcm) for (i = 0; i < multi->channels_count; i++) { snd_pcm_multi_channel_t *bind = &multi->channels[i]; - unsigned int slave_channels = - multi->slaves[bind->slave_idx].channels_count; + unsigned int slave_channels; snd_pcm_chmap_query_t **p; + if (bind->slave_idx < 0) { + maps[0]->map.pos[i] = SND_CHMAP_UNKNOWN; + continue; + } + slave_channels = + multi->slaves[bind->slave_idx].channels_count; + for (p = slave_maps[bind->slave_idx]; *p; p++) { if ((*p)->map.channels == slave_channels) { maps[0]->map.pos[i] = @@ -927,6 +933,10 @@ static snd_pcm_chmap_t *snd_pcm_multi_get_chmap(snd_pcm_t *pcm) map->channels = multi->channels_count; for (i = 0; i < multi->channels_count; i++) { snd_pcm_multi_channel_t *bind = &multi->channels[i]; + if (bind->slave_idx < 0) { + map->pos[i] = SND_CHMAP_UNKNOWN; + continue; + } map->pos[i] = slave_maps[bind->slave_idx]->pos[bind->slave_channel]; } err = 0; @@ -966,6 +976,8 @@ static int snd_pcm_multi_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map) for (i = 0; i < multi->channels_count; i++) { snd_pcm_multi_channel_t *bind = &multi->channels[i]; + if (bind->slave_idx < 0) + continue; slave_maps[bind->slave_idx]->pos[bind->slave_channel] = map->pos[i]; }