From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 6A0541FF178 for ; Mon, 15 Dec 2025 09:14:25 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4593129A7; Mon, 15 Dec 2025 09:15:08 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 15 Dec 2025 09:14:16 +0100 Message-ID: <20251215081435.472283-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH storage] api: status: try to prevent converting integers to floating point X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Since perl can have multiple internal representations for the same scalar variables, it calculates and caches them on demand. So when doing a division with a variable, it calculates and caches the floating point representation of it. When using JSON::XS (which is the default and what we use), it has to look at the internal representation and chooses a format, and if both integer and floating point representations are there it chooses, floating point. This is usually not a problem, but for bigger numbers this representation changes to the format `1.234e+15`. Since our API designates the `total` and `used` fields as integers, our Schema2Rust code wants to de-serialize this as an integer again and fails with such values. (And with this the PDM de-serialization) To avoid this internal conversion, extract the variables before doing division with it, so the original object is not touched. There might be more places where we do such calculations, but it's hard to search for them, so let's fix it as we find them. (And comment to avoid accidental refactoring to the broken code) Example perl code to reproduce the problem: ``` use JSON; my $foo = 12057594037927909; print JSON::encode_json($foo); ``` returns `12057594037927909`, but ``` use JSON; my $foo = 12057594037927909; my $bar = 123.123 / $foo; print JSON::encode_json($foo); ``` return `1.20575940379279e+16`. This was reported in the PDM forum: https://forum.proxmox.com/threads/177888/ Signed-off-by: Dominik Csapak --- src/PVE/API2/Storage/Status.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index 31bcc6d..8225c3a 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -257,7 +257,10 @@ __PACKAGE__->register_method({ } if ($data->{total}) { - $data->{used_fraction} = ($data->{used} // 0) / $data->{total}; + # extract variables, otherwise the division converts used and total to floating points + my $total = $data->{total}; + my $used = $data->{used} // 0; + $data->{used_fraction} = $used / $total; } $res->{$storeid} = $data; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel