mirror of
https://github.com/mpv-player/mpv
synced 2025-02-10 00:47:38 +00:00
ao_coreaudio: fix potential UB in error cases
mNumberChannelDescriptions being 0 is pretty much an error, but if it can happen, then the code checking the chmap below will trigger UB, as chmap is not initialized at all. Also, simplify the code a little: we never change the number of channels, so this is just fine.
This commit is contained in:
parent
81109dcbb6
commit
72d3c5ef00
@ -151,6 +151,7 @@ static bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chmap->num = l->mNumberChannelDescriptions;
|
||||||
for (int n = 0; n < l->mNumberChannelDescriptions; n++) {
|
for (int n = 0; n < l->mNumberChannelDescriptions; n++) {
|
||||||
AudioChannelLabel label = l->mChannelDescriptions[n].mChannelLabel;
|
AudioChannelLabel label = l->mChannelDescriptions[n].mChannelLabel;
|
||||||
int speaker = ca_label_to_mp_speaker_id(label);
|
int speaker = ca_label_to_mp_speaker_id(label);
|
||||||
@ -158,10 +159,8 @@ static bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
|
|||||||
MP_VERBOSE(ao, "channel label=%u unusable to build channel "
|
MP_VERBOSE(ao, "channel label=%u unusable to build channel "
|
||||||
"bitmap, skipping layout\n", (unsigned) label);
|
"bitmap, skipping layout\n", (unsigned) label);
|
||||||
goto coreaudio_error;
|
goto coreaudio_error;
|
||||||
} else {
|
|
||||||
chmap->speaker[n] = speaker;
|
|
||||||
chmap->num = n + 1;
|
|
||||||
}
|
}
|
||||||
|
chmap->speaker[n] = speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free(talloc_ctx);
|
talloc_free(talloc_ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user