From 6bfe9a362c1a3c6e73d586f57b7195636887c041 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Tue, 21 Jun 2022 23:08:03 +0300 Subject: [PATCH] audioconvert: avoid crash on 64 channels + monitor enabled this->monitor enabled adds an additional port in reconfigure_mode. If there was already the maximum 64, this will crash. Make maximum number of ports one larger than max channels to avoid problems. --- spa/plugins/audioconvert/audioconvert.c | 6 ++++-- spa/plugins/audioconvert/test-audioconvert.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index a6517b003..46e658ec6 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -60,7 +60,7 @@ static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audioconvert"); #define MAX_ALIGN FMT_OPS_MAX_ALIGN #define MAX_BUFFERS 32 #define MAX_DATAS SPA_AUDIO_MAX_CHANNELS -#define MAX_PORTS SPA_AUDIO_MAX_CHANNELS +#define MAX_PORTS (SPA_AUDIO_MAX_CHANNELS+1) #define DEFAULT_MUTE false #define DEFAULT_VOLUME VOLUME_NORM @@ -299,6 +299,8 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p struct port *port = GET_PORT(this, direction, port_id); const char *name; + spa_assert(port_id < MAX_PORTS); + if (port == NULL) { port = calloc(1, sizeof(struct port)); if (port == NULL) @@ -1547,7 +1549,7 @@ static int port_enum_formats(void *object, SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int( rate, 1, INT32_MAX), SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int( - DEFAULT_CHANNELS, 1, MAX_PORTS)); + DEFAULT_CHANNELS, 1, SPA_AUDIO_MAX_CHANNELS)); } break; default: diff --git a/spa/plugins/audioconvert/test-audioconvert.c b/spa/plugins/audioconvert/test-audioconvert.c index 72ae39d1f..ffe7bea58 100644 --- a/spa/plugins/audioconvert/test-audioconvert.c +++ b/spa/plugins/audioconvert/test-audioconvert.c @@ -43,7 +43,7 @@ SPA_LOG_IMPL(logger); extern const struct spa_handle_factory test_source_factory; -#define MAX_PORTS SPA_AUDIO_MAX_CHANNELS +#define MAX_PORTS (SPA_AUDIO_MAX_CHANNELS+1) struct context { struct spa_handle *convert_handle;