From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3587A1FF14C for ; Fri, 15 May 2026 09:52:45 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CFD48EF5E; Fri, 15 May 2026 09:52:42 +0200 (CEST) From: David Riley To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager v2] fix #3936: ui: storage: add validation for ZFS blocksize Date: Fri, 15 May 2026 09:51:59 +0200 Message-ID: <20260515075159.45099-1-d.riley@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778831520853 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.295 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: MUTG6QMLA4KBAZP4HKTUC747E2VQ5JDF X-Message-ID-Hash: MUTG6QMLA4KBAZP4HKTUC747E2VQ5JDF X-MailFrom: d.riley@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Riley X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add validation to the ZFS storage blocksize form field to prevent misconfigurations. Validation [0][1]: * Range: 512 bytes to 16 MiB * Format: Allow positive integers with optional 'k' or 'm' suffix. * Constraint: Must be a power of two. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=3936 [0] https://openzfs.github.io/openzfs-docs/man/v2.4/7/zfsprops.7.html#volblocksize [1] https://openzfs.github.io/openzfs-docs/man/v2.4/7/zfsprops.7.html#recordsize Reviewed-by: Fiona Ebner Signed-off-by: David Riley --- Notes: v2: * Renamed function to follow the style guide (camelCase) * combined checks power-of-two and range check * Adapted error message www/manager6/Utils.js | 28 ++++++++++++++++++++++++++++ www/manager6/storage/ZFSEdit.js | 1 + www/manager6/storage/ZFSPoolEdit.js | 1 + 3 files changed, 30 insertions(+) diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index 01e80682..2ed4e65d 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -274,6 +274,34 @@ Ext.define('PVE.Utils', { return ' ' + value; }, + validateZfsBlocksize: function (value) { + if (!value) { + return true; + } + + let match = value.match(/^([1-9][0-9]*)([km])?$/i); + if (!match) { + return gettext( + 'Invalid format. Use numbers with optional k or m suffix (e.g., 16k).', + ); + } + + let bytes = parseInt(match[1], 10); + let suffix = match[2]?.toLowerCase(); + + if (suffix === 'k') { + bytes *= 1024; + } else if (suffix === 'm') { + bytes *= 1024 * 1024; + } + + if (bytes < 512 || (bytes & (bytes - 1)) !== 0 || bytes > 16 * 1024 * 1024) { + return gettext('Value must be a power of 2 between 512 and 16m'); + } + + return true; + }, + render_pbs_fingerprint: (fp) => fp.substring(0, 23), render_backup_encryption: function (v, meta, record) { diff --git a/www/manager6/storage/ZFSEdit.js b/www/manager6/storage/ZFSEdit.js index e9d24642..0d7a971c 100644 --- a/www/manager6/storage/ZFSEdit.js +++ b/www/manager6/storage/ZFSEdit.js @@ -67,6 +67,7 @@ Ext.define('PVE.storage.ZFSInputPanel', { value: '4k', fieldLabel: gettext('Block Size'), allowBlank: false, + validator: PVE.Utils.validateZfsBlocksize, }, { xtype: me.isCreate ? 'textfield' : 'displayfield', diff --git a/www/manager6/storage/ZFSPoolEdit.js b/www/manager6/storage/ZFSPoolEdit.js index 0066dfef..6789b9a3 100644 --- a/www/manager6/storage/ZFSPoolEdit.js +++ b/www/manager6/storage/ZFSPoolEdit.js @@ -106,6 +106,7 @@ Ext.define('PVE.storage.ZFSPoolInputPanel', { emptyText: '16k', fieldLabel: gettext('Block Size'), allowBlank: true, + validator: PVE.Utils.validateZfsBlocksize, }, ], }); -- 2.47.3