From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 930721FF0BC for ; Wed, 02 Dec 2026 15:21:12 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5ED2B219AB; Wed, 02 Dec 2026 15:20:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dualfroz.com; s=dkim; t=1796221100; h=from:subject:date:message-id:to:mime-version: content-transfer-encoding; bh=38kNn2bFMDoX+HBvIJq/P8EcD+g9VShRLiWlWcc5VBo=; b=HcNDcp5myNowzBpdH6O2VJq7EJKKNVx10kdmNGGdGI1mLHI6Q6Q9rwZ5JsoWXhSGnfk9Sq bPr8ZPQmQ2oALE5PIAvKBAm8qGLib3DvzKJlVXXLCKXM3vyzTpbonuthd/FWUCe+i9zKtX if2vHAl0DBWazc3sjcPIcfN86dpBnHy0ctyItZ0J7gfkcGvnM1W6frmJ1bWmgWZFkfDRbj Mt0qzW+9szJfkIIz+kvp1Ertf9hmRcKzu0HHGH8wWvJR3SqYfvSJHnEoTkYFAtRfV6Y6bA XnN6KziG30hqZFrLh71aKeDRdogCq1QRgpBTpO+iqQAacQ+yhg81q1vRrswllA== From: Michal Fox To: pve-devel@lists.proxmox.com Subject: [PATCH storage] fix #5805: plugin: file size info: handle missing fields in qemu-img output Date: Wed, 2 Dec 2026 14:18:06 +0000 Message-ID: <20261202141806.7-1-me@dualfroz.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.115 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy 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: DGCDIYIAKL67YRFLZFZY3NL6YP6JDQM7 X-Message-ID-Hash: DGCDIYIAKL67YRFLZFZY3NL6YP6JDQM7 X-MailFrom: me@dualfroz.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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If qemu-img info works in general but does not report e.g. the actual size of a partially broken image, the untaint checks run on undef and emit a series of "use of uninitialized value" warnings before dying, which are a red herring and do not even name the affected file. Check the required fields first and go through the existing error handling, so the warning (or the error for untrusted images) names the missing field and the file. Add tests for that. Signed-off-by: Michal Fox --- tested with the new src/test/file_size_info_test.pm (fails on master with the uninitialized warnings, passes with the patch); run_plugin_tests.pl gives the same result before and after in my container src/PVE/Storage/Plugin.pm | 5 +++ src/test/file_size_info_test.pm | 62 +++++++++++++++++++++++++++++++++ src/test/run_plugin_tests.pl | 1 + 3 files changed, 68 insertions(+) create mode 100644 src/test/file_size_info_test.pm diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index a97f361..7690f24 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1444,6 +1444,11 @@ sub file_size_info { my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)}; + for my $key (qw(virtual-size format actual-size)) { + return $handle_error->("qemu-img info did not report '$key' for '$filename'\n") + if !defined($info->{$key}); + } + die "backing file not allowed for untrusted image '$filename'!\n" if $untrusted && $parent; ($size) = ($size =~ /^(\d+)$/); # untaint diff --git a/src/test/file_size_info_test.pm b/src/test/file_size_info_test.pm new file mode 100644 index 0000000..48840b8 --- /dev/null +++ b/src/test/file_size_info_test.pm @@ -0,0 +1,62 @@ +package PVE::Storage::TestFileSizeInfo; + +use strict; +use warnings; + +use lib qw(..); + +use File::Temp; +use JSON qw(encode_json); +use PVE::Storage::Plugin; +use Test::MockModule; +use Test::More; + +my $image = File::Temp->new(); +my $filename = $image->filename; + +my $qemu_img_info; +my $mock_common = Test::MockModule->new('PVE::Storage::Common'); +$mock_common->redefine(qemu_img_info => sub { return encode_json($qemu_img_info); }); + +my $complete_info = { + 'virtual-size' => 4194304, + 'actual-size' => 4096, + format => 'raw', +}; + +my sub run_file_size_info { + my ($info, $untrusted) = @_; + + $qemu_img_info = $info; + my @warnings; + local $SIG{__WARN__} = sub { push @warnings, $_[0]; }; + my @res = eval { PVE::Storage::Plugin::file_size_info($filename, undef, 'raw', $untrusted) }; + + return (\@res, $@, \@warnings); +} + +{ + my ($res, $err, $warnings) = run_file_size_info($complete_info); + is($err, '', 'complete info - no error'); + is_deeply([$res->@[0 .. 2]], [4194304, 'raw', 4096], 'complete info - size, format and used'); + is_deeply($warnings, [], 'complete info - no warnings'); +} + +for my $key (qw(actual-size virtual-size format)) { + my $info = { $complete_info->%* }; + delete $info->{$key}; + my $expected_msg = "qemu-img info did not report '$key' for '$filename'\n"; + + my ($res, $err, $warnings) = run_file_size_info($info); + is($err, '', "missing $key - no error for trusted image"); + ok(!defined($res->[0]), "missing $key - no size returned"); + is_deeply($warnings, [$expected_msg], "missing $key - single warning naming the file"); + + ($res, $err, $warnings) = run_file_size_info($info, 1); + is($err, $expected_msg, "missing $key - untrusted image dies naming the file"); + is_deeply($warnings, [], "missing $key - no warnings for untrusted image"); +} + +done_testing(); + +1; diff --git a/src/test/run_plugin_tests.pl b/src/test/run_plugin_tests.pl index da0d0de..029b668 100755 --- a/src/test/run_plugin_tests.pl +++ b/src/test/run_plugin_tests.pl @@ -21,6 +21,7 @@ my $res = $harness->runtests( "free_image_test.pm", "zfs_list_zvol_test.pm", "content_types_test.pm", + "file_size_info_test.pm", "plugin_metadata_test.pm", "plugin_isolation_test.pm", "plugin_load_test.pm", -- 2.43.0