From 33d96adbceb22637b2cff79b9144567dfb2888f7 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 26 Aug 2026 20:59:56 +0200 Subject: [PATCH] Validate that the total disk buffer memory does not exceed 256 MiB --- cmdline/state.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmdline/state.c b/cmdline/state.c index cdee4e99..6bd8a842 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -224,6 +224,18 @@ static void state_config_check(struct snapraid_state* state, const char* path, t { tommy_node* i; unsigned l, s; + size_t disk_count; + + /* check total memory budget for block buffers (max 256 MiB) */ + disk_count = tommy_list_count(&state->disklist) + state->level; + if (disk_count > (256 * 1024) / (state->block_size / KIBI)) { + /* LCOV_EXCL_START */ + log_fatal(EUSER, "The combination of %zu disks and %u KiB 'blocksize' in '%s' exceeds the 256 MiB limit.\n", + disk_count, state->block_size / KIBI, path); + log_fatal(EUSER, "Please reduce the 'blocksize' or the number of disks.\n"); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } /* check for parity level */ if (state->raid_mode == RAID_MODE_VANDERMONDE_RAID) {