From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id EB8C01FF0E1 for ; Mon, 13 Jul 2026 15:24:08 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id B42A42144B; Mon, 13 Jul 2026 15:24:08 +0200 (CEST) From: Robert Obkircher To: pbs-devel@lists.proxmox.com Subject: [PATCH v1 proxmox-backup 2/3] datastore: check that .i.bad files from S3 actually match that pattern Date: Mon, 13 Jul 2026 15:22:25 +0200 Message-ID: <20260713132338.170565-3-r.obkircher@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713132338.170565-1-r.obkircher@proxmox.com> References: <20260713132338.170565-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: 1783949030730 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.321 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_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: W7JEOMNPH2HDFHSKWJI7Y6LLGEKZCE5I X-Message-ID-Hash: W7JEOMNPH2HDFHSKWJI7Y6LLGEKZCE5I 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: Compare the characters, not just the length, and introduce a helper that can be tested in isolation. Signed-off-by: Robert Obkircher --- pbs-datastore/src/chunk_store.rs | 21 ++++++++++++++------- pbs-datastore/src/datastore.rs | 7 +++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pbs-datastore/src/chunk_store.rs b/pbs-datastore/src/chunk_store.rs index a936f5034..f40c58f7e 100644 --- a/pbs-datastore/src/chunk_store.rs +++ b/pbs-datastore/src/chunk_store.rs @@ -360,13 +360,7 @@ impl ChunkStore { } // i-th bad chunk - if bytes.len() == 64 + ".i.bad".len() - && bytes[64] == b'.' - && bytes[65] >= b'0' - && bytes[65] <= b'9' - && bytes[66] == b'.' - && bytes.ends_with(b"bad") - { + if is_bad_chunk_suffix(&bytes[64..]) { return Some((Ok(entry), percentage, ChunkExt::Bad)); } @@ -1028,6 +1022,19 @@ impl ChunkExt { } } +pub fn is_bad_chunk_suffix(s: &[u8]) -> bool { + s.len() == ".i.bad".len() && s[0] == b'.' && s[1].is_ascii_digit() && &s[2..] == b".bad" +} + +#[test] +fn test_is_bad_chunk_suffix() { + assert!(is_bad_chunk_suffix(".0.bad".as_bytes())); + assert!(is_bad_chunk_suffix(".9.bad".as_bytes())); + for s in [".10.bad", ".a.bad", ".bad", "0.bad", ""] { + assert!(!is_bad_chunk_suffix(s.as_bytes())); + } +} + #[test] fn test_chunk_store1() { use tempfile::TempDir; diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 3079fe833..bac5ce3b4 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -43,7 +43,7 @@ use proxmox_section_config::SectionConfigData; use crate::backup_info::{ BackupDir, BackupGroup, BackupInfo, OLD_LOCKING, PROTECTED_MARKER_FILENAME, }; -use crate::chunk_store::ChunkStore; +use crate::chunk_store::{ChunkStore, is_bad_chunk_suffix}; use crate::dynamic_index::{DynamicIndexReader, DynamicIndexWriter}; use crate::fixed_index::{FixedIndexReader, FixedIndexWriter}; use crate::hierarchy::{ListGroups, ListGroupsType, ListNamespaces, ListNamespacesRecursive}; @@ -2680,13 +2680,12 @@ impl DataStore { // file_name() should always be Some, as objects will have a filename let file_name = path.file_name()?; let bytes = file_name.as_bytes(); - let bad_ext_len = ".0.bad".len(); - let bad_chunk = if bytes.len() == 64 + bad_ext_len { + let bad_chunk = if is_bad_chunk_suffix(&bytes[64..]) { true } else if bytes.len() == 64 { false } else { - return None; + return None; // unexpected suffix }; if !bytes.iter().take(64).all(u8::is_ascii_hexdigit) { return None; -- 2.47.3