[linux] Tests: an archive made with 'tar -C dir -czf x .' (a ./ root entry) is accepted (red: found by the systemd container test)
This commit is contained in:
@@ -129,3 +129,36 @@ fn bad_app_or_version_names_never_reach_the_disk() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_archive_made_with_tar_dot_is_accepted() {
|
||||
// `tar -C dir -czf x.tar.gz .` puts the root itself first, as `./`.
|
||||
let (_d, l) = layout();
|
||||
let mut b = tar::Builder::new(flate2::write::GzEncoder::new(
|
||||
Vec::new(),
|
||||
flate2::Compression::fast(),
|
||||
));
|
||||
let mut dir = tar::Header::new_gnu();
|
||||
dir.set_entry_type(tar::EntryType::Directory);
|
||||
dir.set_mode(0o755);
|
||||
dir.set_size(0);
|
||||
b.append_data(&mut dir, "./", &[][..]).unwrap();
|
||||
let mut f = tar::Header::new_gnu();
|
||||
f.set_entry_type(tar::EntryType::Regular);
|
||||
f.set_mode(0o755);
|
||||
f.set_size(3);
|
||||
b.append_data(
|
||||
&mut f,
|
||||
"./run.sh",
|
||||
&b"#!
|
||||
"[..],
|
||||
)
|
||||
.unwrap();
|
||||
let a = b.into_inner().unwrap().finish().unwrap();
|
||||
let dir = unpack(&l, "demo", "1.0.0", &a[..], "s").unwrap();
|
||||
assert_eq!(
|
||||
std::fs::read(dir.join("run.sh")).unwrap(),
|
||||
b"#!
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -223,6 +223,11 @@ fn archive_entries_stay_inside_the_release() {
|
||||
check_entry(EntryKind::File, "bin/shop", 10).unwrap();
|
||||
check_entry(EntryKind::Dir, "static/", 0).unwrap();
|
||||
check_entry(EntryKind::File, "./README", 10).unwrap();
|
||||
// `tar -C dir -czf x.tar.gz .` writes the root itself as `./`: allowed, and it names nothing.
|
||||
assert!(check_entry(EntryKind::Dir, "./", 0).unwrap().is_empty());
|
||||
assert!(check_entry(EntryKind::Dir, ".", 0).unwrap().is_empty());
|
||||
assert!(check_entry(EntryKind::File, "./", 0).is_err());
|
||||
assert!(check_entry(EntryKind::File, ".", 0).is_err());
|
||||
for (kind, path) in [
|
||||
(EntryKind::File, "/etc/passwd"),
|
||||
(EntryKind::File, "../outside"),
|
||||
|
||||
Reference in New Issue
Block a user