Skip to content

Commit ca540f5

Browse files
yeetypetecgwalters
authored andcommitted
tar: Drop PAX path/linkpath headers that bypass /etc remap
PAX extended headers take precedence over basic tar header fields per POSIX. When a container layer contains PAX `path` or `linkpath` headers (e.g. for non-ASCII filenames), they override the remapped path written to the basic header, causing files that should land under /usr/etc to remain under /etc. Filter out `path` and `linkpath` from PAX extensions before writing the output entry. The tar crate regenerates them from the remapped path passed to append_data/append_link. Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
1 parent 8cdf141 commit ca540f5

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

crates/ostree-ext/src/tar/write.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,23 @@ pub(crate) fn copy_entry(
4848
};
4949
let mut header = entry.header().clone();
5050
if let Some(headers) = entry.pax_extensions()? {
51-
let extensions = headers
51+
// Filter out `path` and `linkpath` from PAX extensions. The tar crate
52+
// will regenerate them from the (possibly remapped) path we pass to
53+
// append_data/append_link. Keeping the originals would override our
54+
// remap (e.g. /etc -> /usr/etc) since PAX headers take precedence
55+
// over basic tar header fields per POSIX.
56+
let extensions: Vec<_> = headers
5257
.map(|ext| {
5358
let ext = ext?;
5459
Ok((ext.key()?, ext.value_bytes()))
5560
})
56-
.collect::<Result<Vec<_>>>()?;
57-
dest.append_pax_extensions(extensions.as_slice().iter().copied())?;
61+
.collect::<Result<Vec<_>>>()?
62+
.into_iter()
63+
.filter(|(key, _)| *key != "path" && *key != "linkpath")
64+
.collect();
65+
if !extensions.is_empty() {
66+
dest.append_pax_extensions(extensions.iter().copied())?;
67+
}
5868
}
5969

6070
// Need to use the entry.link_name() not the header.link_name()

0 commit comments

Comments
 (0)