all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20261117152814.491323-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20261117152814.491323-1-c.ebner@proxmox.com>

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 <c.ebner@proxmox.com>
---
 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::<PayloadRef>() 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<T: Clone + ReadAt> AccessorImpl<T> {
 
         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<T: Clone + ReadAt> AccessorImpl<T> {
                 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<T: Clone + ReadAt> 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<u8>, Vec<u8>)> {
     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<usize> = 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::<u64>();
+    let size_bytes = &mut archive[size_pos..size_pos + size_of::<u64>()];
+    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<u64> {
+    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





  parent reply	other threads:[~2026-11-17 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:28 [PATCH proxmox-backup/pxar 00/10] fix #8319: support split pxar archives in proxmox-backup-debug diff Christian Ebner
2026-11-17 15:28 ` [PATCH pxar 01/10] encoder: record metadata-only goodbye size for split archive files Christian Ebner
2026-11-17 15:28 ` Christian Ebner [this message]
2026-11-17 15:28 ` [PATCH pxar 03/10] accessor: add convenience helper to get content's byte range Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 04/10] datastore: index: return dedicated type for chunk offset trait method Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 05/10] bin: debug: fix off-by-one error in last chunk lookup Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 06/10] bin: debug: refactore dynamic index reader opening logic into helper Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 07/10] bin: debug: refactor and deduplicate chunk range difference check Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 08/10] fix #8319: bin: debug: support split pxar archives via diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 09/10] bin: debug: use pxar related archive name helpers for diff Christian Ebner
2026-11-17 15:28 ` [PATCH proxmox-backup 10/10] docs: debug: mention split pxar archives for diff subcommand Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117152814.491323-3-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal