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 D42C61FF0AA for ; Tue, 17 Nov 2026 16:28:44 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 33910216AB; Tue, 17 Nov 2026 16:28:35 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH pxar 02/10] accessor: limit split archive file entry ranges to payload reference Date: Tue, 17 Nov 2026 16:28:06 +0100 Message-ID: <20261117152814.491323-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com> References: <20261117152814.491323-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794929310254 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.370 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: R4ENWLM3QIUG57DGXHYJALEFZSCRZQCQ X-Message-ID-Hash: R4ENWLM3QIUG57DGXHYJALEFZSCRZQCQ 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: Archives encoded by older versions record the payload size in the goodbye table size of regular files also for split archives, so the range of such file entries extends past the entry in the metadata archive. Once the payload reference is decoded, the end of the entry in the metadata archive is known. Limit the range to it for decoded file entries, hardlink targets and files opened at a given range. This is backwards compatible with archives still including the file payload size in the goodbye entry. Undecoded directory entries still expose the range as encoded in the goodbye table, as the entry kind is only known after decoding. Signed-off-by: Christian Ebner --- src/accessor/mod.rs | 32 +++++++++++++++------ tests/split.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/accessor/mod.rs b/src/accessor/mod.rs index 5e2169c..02c7a19 100644 --- a/src/accessor/mod.rs +++ b/src/accessor/mod.rs @@ -52,6 +52,22 @@ impl EntryRangeInfo { entry_range, } } + + /// Limit the range of a decoded regular file in a split archive to its payload reference. + /// + /// Older encoders included the payload size in the goodbye table size of such files, letting + /// the range extend past the entry, possibly even past the end of the metadata archive. + fn trim_to_payload_ref(mut self, entry: &Entry) -> Self { + if let EntryKind::File { + offset: Some(offset), + payload_offset: Some(_), + .. + } = entry.kind() + { + self.entry_range.end = offset + size_of::() as u64; + } + self + } } /// Stores a content range to be accessed via the `Accessor` as well as the payload reference to @@ -339,8 +355,8 @@ impl AccessorImpl { Ok(FileEntryImpl { input: self.input.clone(), + entry_range_info: entry_range_info.clone().trim_to_payload_ref(&entry), entry, - entry_range_info: entry_range_info.clone(), caches: Arc::clone(&self.caches), }) } @@ -391,15 +407,15 @@ impl AccessorImpl { size, .. } => { - let meta_size = offset - link_offset; - let entry_end = link_offset + meta_size + size; + let entry_range_info = EntryRangeInfo { + filename_header_offset: Some(link_offset), + entry_range: entry_offset..offset + size, + } + .trim_to_payload_ref(&entry); Ok(FileEntryImpl { input: self.input.clone(), entry, - entry_range_info: EntryRangeInfo { - filename_header_offset: Some(link_offset), - entry_range: entry_offset..entry_end, - }, + entry_range_info, caches: Arc::clone(&self.caches), }) } @@ -892,8 +908,8 @@ impl DirEntryImpl<'_, T> { Ok(FileEntryImpl { input: self.dir.input.clone(), + entry_range_info: self.entry_range_info.clone().trim_to_payload_ref(&entry), entry, - entry_range_info: self.entry_range_info.clone(), caches: Arc::clone(&self.caches), }) } diff --git a/tests/split.rs b/tests/split.rs index 2dc4aa8..2419958 100644 --- a/tests/split.rs +++ b/tests/split.rs @@ -1,5 +1,6 @@ use std::future::Future; use std::io; +use std::ops::Range; use std::path::Path; use std::pin::pin; use std::task::{Context, Poll, Waker}; @@ -7,7 +8,7 @@ use std::task::{Context, Poll, Waker}; use pxar::accessor::sync::{Accessor, FileEntry}; use pxar::encoder::PayloadOffset; use pxar::encoder::sync::{Encoder, StandardWriter}; -use pxar::format::{GoodbyeItem, Header}; +use pxar::format::{self, GoodbyeItem, Header}; use pxar::{EntryKind, Metadata, PxarVariant}; const NEW_FILE: &str = "a_new.txt"; @@ -66,6 +67,27 @@ fn encode_archive(split: bool) -> io::Result<(Vec, Vec)> { Ok((archive, payload)) } +/// Inflate the goodbye table size of the given file as done by encoders including the payload +/// size also for split archives. +fn inflate_goodbye_size(archive: &mut [u8], file_name: &str, payload_size: u64) { + let hash = format::hash_filename(file_name.as_bytes()).to_le_bytes(); + let positions: Vec = archive + .windows(hash.len()) + .enumerate() + .filter_map(|(pos, window)| (window == hash).then_some(pos)) + .collect(); + assert_eq!( + positions.len(), + 1, + "goodbye item for {file_name} not unique" + ); + + let size_pos = positions[0] + 2 * size_of::(); + let size_bytes = &mut archive[size_pos..size_pos + size_of::()]; + let size = u64::from_le_bytes(size_bytes.try_into().unwrap()) + payload_size; + size_bytes.copy_from_slice(&size.to_le_bytes()); +} + fn open_accessor<'a>(archive: &'a [u8], payload: &'a [u8], split: bool) -> Accessor<&'a [u8]> { let input = if split { PxarVariant::Split(archive, (payload, payload.len() as u64)) @@ -102,6 +124,15 @@ fn check_entry_ranges(accessor: &Accessor<&[u8]>, archive: &[u8], split: bool) { "range of {NEW_FILE} does not end at the following entry", ); + let target = accessor + .follow_hardlink(&hardlink) + .expect("failed to follow hardlink"); + assert_eq!( + target.entry_range_info().entry_range, + new_file.entry_range_info().entry_range, + "hardlink target range differs from the file's range", + ); + if split { let reused_file = lookup_file(accessor, REUSED_FILE); assert_eq!( @@ -124,6 +155,13 @@ fn check_entry_ranges(accessor: &Accessor<&[u8]>, archive: &[u8], split: bool) { } } +fn file_range(accessor: &Accessor<&[u8]>, name: &str) -> Range { + lookup_file(accessor, name) + .entry_range_info() + .entry_range + .clone() +} + #[test] fn unified_entry_ranges() { let (archive, _) = encode_archive(false).expect("failed to encode archive"); @@ -150,3 +188,33 @@ fn split_entry_ranges() { ); } } + +#[test] +fn split_entry_ranges_with_inflated_goodbye_size() { + let (archive, payload) = encode_archive(true).expect("failed to encode archive"); + let expected = file_range(&open_accessor(&archive, &payload, true), NEW_FILE); + + let mut inflated = archive.clone(); + inflate_goodbye_size(&mut inflated, NEW_FILE, NEW_FILE_SIZE); + let accessor = open_accessor(&inflated, &payload, true); + + // The undecoded directory entry still exposes the range as recorded in the goodbye table. + let root = accessor.open_root().expect("failed to open root"); + let dir_entry = root + .read_dir() + .map(|entry| entry.expect("failed to read directory entry")) + .find(|entry| entry.file_name() == Path::new(NEW_FILE)) + .expect("directory entry not found"); + let inflated_info = dir_entry.entry_range_info().clone(); + assert_eq!(inflated_info.entry_range.end, expected.end + NEW_FILE_SIZE); + assert!(inflated_info.entry_range.end > root_goodbye_start(&inflated, 3)); + + let decoded = dir_entry.decode_entry().expect("failed to decode entry"); + assert_eq!(decoded.entry_range_info().entry_range, expected); + + check_entry_ranges(&accessor, &inflated, true); + + let opened = + unsafe { accessor.open_file_at_range(&inflated_info) }.expect("failed to open file"); + assert_eq!(opened.entry_range_info().entry_range, expected); +} -- 2.47.3