config/PartitionConfig: clip the max_playlist_length setting

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1932
This commit is contained in:
Max Kellermann 2024-04-03 21:43:31 +02:00
parent 41a1e98cb9
commit 08a00ee21b
2 changed files with 8 additions and 0 deletions

View File

@ -10,4 +10,11 @@ PartitionConfig::PartitionConfig(const ConfigData &config)
queue.max_length =
config.GetPositive(ConfigOption::MAX_PLAYLIST_LENGTH,
QueueConfig::DEFAULT_MAX_LENGTH);
if (queue.max_length > QueueConfig::MAX_MAX_LENGTH)
/* silently clip max_playlist_length to a resonable
limit to avoid out-of-memory during startup (or
worse, an integer overflow because the allocation
size is larger than SIZE_MAX) */
queue.max_length = QueueConfig::MAX_MAX_LENGTH;
}

View File

@ -5,6 +5,7 @@
struct QueueConfig {
static constexpr unsigned DEFAULT_MAX_LENGTH = 16 * 1024;
static constexpr unsigned MAX_MAX_LENGTH = 16 * 1024 * 1024;
unsigned max_length = DEFAULT_MAX_LENGTH;
};