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 7165E1FF0E6 for ; Fri, 07 Aug 2026 11:58:36 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 41F1D21562; Fri, 07 Aug 2026 11:58:36 +0200 (CEST) From: Robert Obkircher To: pbs-devel@lists.proxmox.com Subject: [PATCH v1 proxmox-backup 1/2] datastore: prefer standard library over custom unsafe code Date: Fri, 7 Aug 2026 11:57:59 +0200 Message-ID: <20260807095803.3051-2-r.obkircher@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260807095803.3051-1-r.obkircher@proxmox.com> References: <20260807095803.3051-1-r.obkircher@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1786096697941 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.914 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: AU753WGIGBADNWM2CPPUTEGYSL5SKU5Q X-Message-ID-Hash: AU753WGIGBADNWM2CPPUTEGYSL5SKU5Q X-MailFrom: r.obkircher@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: 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}"))?; // going from unencrypted to encrypted can never be right, since the digest // includes data derived from the encryption key -- 2.47.3