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 395CB1FF13B for ; Wed, 25 Feb 2026 13:05:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 130D7374B1; Wed, 25 Feb 2026 13:06:32 +0100 (CET) From: Markus Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2 2/3] agent: file-read: Allow maintaining base64-encoding of content Date: Wed, 25 Feb 2026 12:28:48 +0100 Message-ID: <20260225112851.124188-3-info@ebner-markus.de> In-Reply-To: <20260225112851.124188-1-info@ebner-markus.de> References: <20260225112851.124188-1-info@ebner-markus.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.425 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_PASS -0.1 DMARC pass policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 1.113 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.358 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.659 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 X-MailFrom: info@ebner-markus.de X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation Message-ID-Hash: MF3DZ775CX7UOBSZKTX24QEKGCSIH7KG X-Message-ID-Hash: MF3DZ775CX7UOBSZKTX24QEKGCSIH7KG X-Mailman-Approved-At: Wed, 25 Feb 2026 13:06:35 +0100 CC: Markus Ebner X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The previous implementation always decoded the base64-encoded content received from the qemu-guest-agent file-read call. Since JSON strings must be comliant unicode text, binary data got escaped using unicode escape sequences, using the pattern: \u00XX - with XX being the hex value of the byte to encode. For certain binary files, this lead to a massively inflated payload size of the API response. Comparison on my test system: For a 4MiB test-file generated using dd if=/dev/urandom bs=4M count=1 - Reading it with decode=1 transfers 8.61MiB and takes 5700ms on avg. - Reading it with decode=0 transfers 5.59MiB and takes 3300ms on avg. To be backwards compatible, the decode parameter defaults to 1. Signed-off-by: Markus Ebner --- src/PVE/API2/Qemu/Agent.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/Qemu/Agent.pm b/src/PVE/API2/Qemu/Agent.pm index f32e1dc2..1f5962e9 100644 --- a/src/PVE/API2/Qemu/Agent.pm +++ b/src/PVE/API2/Qemu/Agent.pm @@ -472,6 +472,15 @@ __PACKAGE__->register_method({ default => $MAX_READ_SIZE, description => "Number of bytes to read.", }, + decode => { + type => 'boolean', + optional => 1, + default => 1, + description => "Data received from the QEMU Guest-Agent is base64 encoded." + . " If this is set to true, the data is decoded." + . " Otherwise the content is forwarded with base64 encoding." + . " Defaults to true.", + }, file => { type => 'string', description => 'The path to the file', @@ -496,6 +505,7 @@ __PACKAGE__->register_method({ code => sub { my ($param) = @_; my $count = int($param->{count} // $MAX_READ_SIZE); + my $decode = $param->{decode} // 1; my $vmid = $param->{vmid}; my $conf = PVE::QemuConfig->load_config($vmid); @@ -515,7 +525,10 @@ __PACKAGE__->register_method({ mon_cmd($vmid, "guest-file-read", handle => $qgafh, count => int($chunk_size)); check_agent_error($read, "can't read from file"); - $content .= decode_base64($read->{'buf-b64'}); + my $chunk = $read->{'buf-b64'}; + $chunk = decode_base64($chunk) if $decode; + $content .= $chunk; + $bytes_read += $read->{count}; $eof = $read->{eof} // 0; } -- 2.53.0