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 8FAF11FF0E6 for ; Fri, 07 Aug 2026 14:43:53 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CEF652156D; Fri, 07 Aug 2026 14:43:51 +0200 (CEST) Message-ID: <7e18f51d-505b-43bb-b52f-3c7cb878186f@proxmox.com> Date: Fri, 7 Aug 2026 14:43:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Christian Ebner Subject: Re: [PATCH v1 proxmox-backup 1/2] datastore: prefer standard library over custom unsafe code To: Robert Obkircher , pbs-devel@lists.proxmox.com References: <20260807095803.3051-1-r.obkircher@proxmox.com> <20260807095803.3051-2-r.obkircher@proxmox.com> Content-Language: en-US, de-DE In-Reply-To: <20260807095803.3051-2-r.obkircher@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1786106615473 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.921 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: R3WU4HLVL4XF7UNGKKQUFKYIM2ZRUSEG X-Message-ID-Hash: R3WU4HLVL4XF7UNGKKQUFKYIM2ZRUSEG X-MailFrom: c.ebner@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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 8/7/26 11:58 AM, Robert Obkircher wrote: > The allocation is unnecessary overhead, and the unsafe code in > read_exact_allocated looks a bit dangerous. > > Signed-off-by: Robert Obkircher > --- > pbs-datastore/src/chunk_store.rs | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs > index 6d2ffdbde..3f637730c 100644 > --- a/pbs-datastore/src/chunk_store.rs > +++ b/pbs-datastore/src/chunk_store.rs > @@ -1,3 +1,4 @@ > +use std::io::Read; > use std::os::unix::fs::MetadataExt; > use std::os::unix::io::AsRawFd; > use std::path::{Path, PathBuf}; > @@ -10,7 +11,6 @@ use tracing::{info, warn}; > > use pbs_api_types::{DatastoreFSyncLevel, GarbageCollectionStatus}; > use pbs_config::BackupLockGuard; > -use proxmox_io::ReadExt; > use proxmox_s3_client::S3Client; > use proxmox_sys::fs::{CreateOptions, create_dir, create_path, file_type_from_file_stat}; > use proxmox_sys::process_locker::{ > @@ -708,8 +708,11 @@ impl ChunkStore { > } > } else if chunk.is_encrypted() { > // incoming chunk is encrypted, possible attack or hash collision! > - let mut existing_file = std::fs::File::open(&chunk_path)?; > - let magic = existing_file.read_exact_allocated(8)?; > + > + let mut magic = [0u8; 8]; > + std::fs::File::open(&chunk_path) > + .and_then(|mut f| f.read_exact(&mut magic)) > + .map_err(|e| format_err!("Failed to read header of existing chunk '{digest_str}' on store '{name}: {e}"))?; nit: this does not read the chunk header (DataBlobHeader/EncryptedDataBlobHeader), just the magic number. So maybe better to also refer to it in the error message as such. > > // going from unencrypted to encrypted can never be right, since the digest > // includes data derived from the encryption key