Skip to content

Commit

Permalink
fs: workaround quirkly overlayfs listxattr() (#43)
Browse files Browse the repository at this point in the history
We use listxattr() with an empty buffer (as documented in the manpage)
to query the size of the xattrs that are present.  Unfortunately, this
"empty buffer" case hits a shortcut in the xattr code in overlayfs which
happens before the overlayfs-internal xattrs are filtered out.

Once we perform the read "for real" we hit the filter path and the
returned xattrs are smaller than we were expecting.

Let's deal with that by accepting a smaller return value from the second
call and truncating the buffer to that length.

Thanks to Shawn Wang <[email protected]> for the report.

Closes #41

Signed-off-by: Allison Karlitskaya <[email protected]>
  • Loading branch information
allisonkarlitskaya authored Dec 3, 2024
1 parent 3350a24 commit 77b8b96
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ impl<'repo> FilesystemReader<'repo> {
let names_size = listxattr(&filename, &mut [])?;
let mut names = vec![0; names_size];
let actual_names_size = listxattr(&filename, &mut names)?;

// Can be less than the expected size on overlayfs because of
// https://github.com/containers/composefs-rs/issues/41
ensure!(
actual_names_size == names.len(),
actual_names_size <= names.len(),
"xattrs changed during read"
);
names.truncate(actual_names_size);

let mut buffer = [0; 65536];
for name in names.split_inclusive(|c| *c == 0) {
Expand Down

0 comments on commit 77b8b96

Please sign in to comment.