bluez5: Don't assume channels fit in uint8_t

There is no reason to believe the number of channels can fit in a
uint8_t. Limit the number of channels in some places where it can not
be avoided.
This commit is contained in:
Wim Taymans 2025-04-04 16:05:51 +02:00
parent 74e6e6c29d
commit 532140ca90
2 changed files with 4 additions and 4 deletions

View file

@ -497,7 +497,7 @@ static int get_mapping(const struct media_codec *codec, const a2dp_opus_05_direc
bool use_surround_encoder, uint8_t *streams_ret, uint8_t *coupled_streams_ret,
const uint8_t **surround_mapping, uint32_t *positions)
{
const uint8_t channels = conf->channels;
const uint32_t channels = conf->channels;
const uint32_t location = OPUS_05_GET_LOCATION(*conf);
const uint8_t coupled_streams = conf->coupled_streams;
const uint8_t *permutation = NULL;
@ -561,7 +561,7 @@ static int codec_fill_caps(const struct media_codec *codec, uint32_t flags,
a2dp_opus_05_t a2dp_opus_05 = {
.info = codec->vendor,
.main = {
.channels = SPA_AUDIO_MAX_CHANNELS,
.channels = SPA_MIN(255u, SPA_AUDIO_MAX_CHANNELS),
.frame_duration = (OPUS_05_FRAME_DURATION_25 |
OPUS_05_FRAME_DURATION_50 |
OPUS_05_FRAME_DURATION_100 |
@ -571,7 +571,7 @@ static int codec_fill_caps(const struct media_codec *codec, uint32_t flags,
OPUS_05_INIT_BITRATE(0)
},
.bidi = {
.channels = SPA_AUDIO_MAX_CHANNELS,
.channels = SPA_MIN(255u, SPA_AUDIO_MAX_CHANNELS),
.frame_duration = (OPUS_05_FRAME_DURATION_25 |
OPUS_05_FRAME_DURATION_50 |
OPUS_05_FRAME_DURATION_100 |

View file

@ -903,7 +903,7 @@ static int codec_caps_preference_cmp(const struct media_codec *codec, uint32_t f
static uint8_t channels_to_positions(uint32_t channels, uint32_t *position)
{
uint8_t n_channels = get_channel_count(channels);
uint32_t n_channels = get_channel_count(channels);
uint8_t n_positions = 0;
spa_assert(n_channels <= SPA_AUDIO_MAX_CHANNELS);