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 B2B551FF0AA for ; Tue, 17 Nov 2026 21:42:56 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5CC4A218C8; Tue, 17 Nov 2026 21:40:56 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 19/51] api: status: simplify file content assertion logic for up-/download Date: Tue, 17 Nov 2026 21:38:51 +0100 Message-ID: <20261117203953.913035-20-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794948033359 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.260 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: KOMBRXDRICD6TUY6SUSLR5UDPQOTMTQB X-Message-ID-Hash: KOMBRXDRICD6TUY6SUSLR5UDPQOTMTQB X-MailFrom: m.carrara@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: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Create another helper for the file content assertion logic in the upload / download_url API methods. Absorb the `assert_ova_contents()` helper along the way, since it does not need to be standalone anymore. Signed-off-by: Max R. Carrara --- src/PVE/API2/Storage/Status.pm | 91 ++++++++++++---------------------- 1 file changed, 32 insertions(+), 59 deletions(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index 4ef7755a..f18b64cb 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -100,29 +100,44 @@ my sub parse_transferred_file_path_extension : prototype($$) { } die "upload / download: failed to parse '$path' - unhandled content type '$vtype'\n"; } -my sub assert_ova_contents { - my ($file) = @_; +my sub assert_file_transfer_contents_valid : prototype($$$) { + my ($path, $vtype, $extension) = @_; - # test if it's really a tar file with an ovf file inside - my $hasOvf = 0; - run_command( - ['tar', '-t', '-f', $file], - outfunc => sub { - my ($line) = @_; + if ($vtype eq 'iso') { + PVE::Storage::assert_iso_content($path); + return; + } - if ($line =~ m/\.ovf$/) { - $hasOvf = 1; - } - }, - ); + if ($vtype eq 'import') { + if ($extension eq 'ova') { + # test if it's really a tar file with an ovf file inside + my $hasOvf = 0; + run_command( + ['tar', '-t', '-f', $path], + outfunc => sub { + my ($line) = @_; - die "ova archive has no .ovf file inside\n" if !$hasOvf; + if ($line =~ m/\.ovf$/) { + $hasOvf = 1; + } + }, + ); - return 1; + die "ova archive has no .ovf file inside\n" if !$hasOvf; + return; + } + + my $is_untrusted = 1; + my $timeout = 10; + + PVE::Storage::file_size_info($path, $timeout, $extension, $is_untrusted); + + return; + } } __PACKAGE__->register_method({ name => 'index', path => '', @@ -644,24 +659,12 @@ __PACKAGE__->register_method({ my $size = -s $tmpfilename; die "temporary file '$tmpfilename' does not exist\n" if !defined($size); my $filename = PVE::Storage::normalize_content_filename($param->{filename}); - - my $is_ova = 0; - my $image_format; - my $extension = parse_transferred_file_path_extension($filename, $content); - if ($content eq 'import') { - if ($extension eq 'ova') { - $is_ova = 1; - } else { - $image_format = $extension; - } - } - # FIXME: Call plugin_get_vtype_subdir() instead of # $plugin->get_subdir() on the next APIAGE reset. my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); my $path = $plugin->get_subdir($scfg, $content); @@ -725,20 +728,11 @@ __PACKAGE__->register_method({ print "\n"; # the front end expects the error to reside at the last line without any noise die "checksum mismatch: got '$checksum_got' != expect '$checksum'\n"; } } - if ($content eq 'iso') { - PVE::Storage::assert_iso_content($tmpfilename); - } - - if ($is_ova) { - assert_ova_contents($tmpfilename); - } elsif (defined($image_format)) { - # checks untrusted image - PVE::Storage::file_size_info($tmpfilename, 10, $image_format, 1); - } + assert_file_transfer_contents_valid($tmpfilename, $content, $extension); }; if (my $err = $@) { # unlinks only the temporary file from the http server unlink $tmpfilename or $! == ENOENT @@ -859,24 +853,12 @@ __PACKAGE__->register_method({ my ($content, $url) = $param->@{ 'content', 'url' }; assert_can_transfer_files($scfg, $storage, $content); my $filename = PVE::Storage::normalize_content_filename($param->{filename}); - - my $is_ova = 0; - my $image_format; - my $extension = parse_transferred_file_path_extension($filename, $content); - if ($content eq 'import') { - if ($extension eq 'ova') { - $is_ova = 1; - } else { - $image_format = $extension; - } - } - # FIXME: Call plugin_get_vtype_subdir() instead of # $plugin->get_subdir() on the next APIAGE reset. my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); my $path = $plugin->get_subdir($scfg, $content); @@ -898,20 +880,11 @@ __PACKAGE__->register_method({ } $opts->{assert_file_validity} = sub { my ($tmp_path) = @_; - if ($content eq 'iso') { - PVE::Storage::assert_iso_content($tmp_path); - } - - if ($is_ova) { - assert_ova_contents($tmp_path); - } elsif (defined($image_format)) { - # checks untrusted image - PVE::Storage::file_size_info($tmp_path, 10, $image_format, 1); - } + assert_file_transfer_contents_valid($tmp_path, $content, $extension); }; my $worker = sub { if ($compression) { die "decompression not supported for $content\n" if $content ne 'iso'; -- 2.47.3