Skip to content

Commit

Permalink
tar/export: Write symlink targets literally
Browse files Browse the repository at this point in the history
Requires: alexcrichton/tar-rs#274

And I'll just copy/paste the commit message from there, lightly edited:

In https://github.com/ostreedev/ostree we generate a cryptographic
checksum over files and symlinks, and directories.

ostree does not currently perform any canonicalization on symlinks;
we'll respect and honor whatever bytes we're provided as input,
and replicate that on the target.

We're using the Rust tar crate to do tar serialization,
which has so far worked fine...except, I hit this corner case:

```
[root@cosa-devsh ~]# rpm -qf /usr/lib/systemd/systemd-sysv-install
chkconfig-1.13-2.el8.x86_64
[root@cosa-devsh ~]# ll /usr/lib/systemd/systemd-sysv-install
lrwxrwxrwx. 2 root root 24 Nov 29 18:08 /usr/lib/systemd/systemd-sysv-install -> ../../..//sbin/chkconfig
[root@cosa-devsh ~]#
```

But, using `set_link_name` to write the tarball, we end up with
the canonicalized path `../../../sbin/chkconfig` - i.e. without the
double `//`.  This breaks the checksum.

Now, I am a bit tempted to change ostree to do canonicalization.  But
even if we did, I'd need to *exactly* match what tar-rs is doing.

(I may of course also try to change the rhel8 systemd package, but
 that's going to take a while to propagate and this corner case isn't
 the only one I'm sure)
  • Loading branch information
cgwalters committed Dec 14, 2021
1 parent 39d4b93 commit 96b693a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -7,3 +7,6 @@ opt-level = 1 # No optimizations are too slow for us.

[profile.release]
lto = "thin"

[patch.crates-io]
tar = { path = "../../alexcrichton/tar-rs" }
20 changes: 15 additions & 5 deletions lib/src/tar/export.rs
Expand Up @@ -231,12 +231,22 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
.append_data(&mut h, &path, &mut instream)
.with_context(|| format!("Writing regfile {}", checksum))?;
} else {
let target = meta.symlink_target().unwrap();
let target = target.as_str();
let context = || format!("Writing content symlink: {}", checksum);
h.set_entry_type(tar::EntryType::Symlink);
h.set_size(0);
self.out
.append_link(&mut h, &path, meta.symlink_target().unwrap().as_str())
.with_context(context)?;
if target.contains("//") {
h.set_link_name_literal(meta.symlink_target().unwrap().as_str())
.with_context(context)?;
self.out
.append_data(&mut h, &path, &mut std::io::empty())
.with_context(context)?;
} else {
h.set_entry_type(tar::EntryType::Symlink);
h.set_size(0);
self.out
.append_link(&mut h, &path, target)
.with_context(context)?;
}
}
}

Expand Down

0 comments on commit 96b693a

Please sign in to comment.