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 9BC5B1FF13A for ; Wed, 22 Jul 2026 16:22:05 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id DABD8214AF; Wed, 22 Jul 2026 16:22:04 +0200 (CEST) Message-ID: <72a28857-5b50-4f23-a0df-37e0bcf5b895@proxmox.com> Date: Wed, 22 Jul 2026 16:22:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Christian Ebner Subject: Re: [PATCH v1 proxmox-backup 2/3] datastore: check that .i.bad files from S3 actually match that pattern To: Robert Obkircher , pbs-devel@lists.proxmox.com References: <20260713132338.170565-1-r.obkircher@proxmox.com> <20260713132338.170565-3-r.obkircher@proxmox.com> Content-Language: en-US, de-DE In-Reply-To: <20260713132338.170565-3-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: 1784730092623 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.179 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: NUXMFGZLVHKQ7KGIM3WYBTYSBZLWORQW X-Message-ID-Hash: NUXMFGZLVHKQ7KGIM3WYBTYSBZLWORQW 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: only one small nit inline, with that addressed: Reviewed-by: Christian Ebner On 7/13/26 3:24 PM, Robert Obkircher wrote: > 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 { nit: this should be pub(crate) only, no callers from outside. > + 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())); > + } > +} > + thanks a lot for the additional tests! > #[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;