From 08a00ee21b891ab8527689e120896766faac6a62 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 3 Apr 2024 21:43:31 +0200 Subject: [PATCH] config/PartitionConfig: clip the max_playlist_length setting Closes https://github.com/MusicPlayerDaemon/MPD/issues/1932 --- src/config/PartitionConfig.cxx | 7 +++++++ src/config/QueueConfig.hxx | 1 + 2 files changed, 8 insertions(+) diff --git a/src/config/PartitionConfig.cxx b/src/config/PartitionConfig.cxx index d3f0182ff..5a275cdc2 100644 --- a/src/config/PartitionConfig.cxx +++ b/src/config/PartitionConfig.cxx @@ -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; } diff --git a/src/config/QueueConfig.hxx b/src/config/QueueConfig.hxx index 8d9183613..8766aa525 100644 --- a/src/config/QueueConfig.hxx +++ b/src/config/QueueConfig.hxx @@ -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; };