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.
This commit is contained in:
Pauli Virtanen 2022-06-21 23:08:03 +03:00 committed by Wim Taymans
parent 0f62d3442c
commit 6bfe9a362c
2 changed files with 5 additions and 3 deletions

View file

@ -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_ALIGN FMT_OPS_MAX_ALIGN
#define MAX_BUFFERS 32 #define MAX_BUFFERS 32
#define MAX_DATAS SPA_AUDIO_MAX_CHANNELS #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_MUTE false
#define DEFAULT_VOLUME VOLUME_NORM #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); struct port *port = GET_PORT(this, direction, port_id);
const char *name; const char *name;
spa_assert(port_id < MAX_PORTS);
if (port == NULL) { if (port == NULL) {
port = calloc(1, sizeof(struct port)); port = calloc(1, sizeof(struct port));
if (port == NULL) if (port == NULL)
@ -1547,7 +1549,7 @@ static int port_enum_formats(void *object,
SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int( SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int(
rate, 1, INT32_MAX), rate, 1, INT32_MAX),
SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int( SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int(
DEFAULT_CHANNELS, 1, MAX_PORTS)); DEFAULT_CHANNELS, 1, SPA_AUDIO_MAX_CHANNELS));
} }
break; break;
default: default:

View file

@ -43,7 +43,7 @@ SPA_LOG_IMPL(logger);
extern const struct spa_handle_factory test_source_factory; 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 context {
struct spa_handle *convert_handle; struct spa_handle *convert_handle;