Skip to content

Commit

Permalink
Add case for ustar header with gnu longname (alexcrichton#224)
Browse files Browse the repository at this point in the history
* Check for any recognized header format when adding entry extended header info

Signed-off-by: David McNeil <mcneil.david2@gmail.com>

* Fix formatting

Signed-off-by: David McNeil <mcneil.david2@gmail.com>
  • Loading branch information
davidMcneil authored and moschroe committed Jun 11, 2020
1 parent f0f3f58 commit 6969cc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ impl<'a> EntriesFields<'a> {
None => return Ok(None),
};

if entry.header().as_gnu().is_some() && entry.header().entry_type().is_gnu_longname() {
let is_recognized_header =
entry.header().as_gnu().is_some() || entry.header().as_ustar().is_some();

if is_recognized_header && entry.header().entry_type().is_gnu_longname() {
if gnu_longname.is_some() {
return Err(other(
"two long name entries describing \
Expand All @@ -298,7 +301,7 @@ impl<'a> EntriesFields<'a> {
continue;
}

if entry.header().as_gnu().is_some() && entry.header().entry_type().is_gnu_longlink() {
if is_recognized_header && entry.header().entry_type().is_gnu_longlink() {
if gnu_longlink.is_some() {
return Err(other(
"two long name entries describing \
Expand All @@ -309,9 +312,7 @@ impl<'a> EntriesFields<'a> {
continue;
}

if entry.header().as_ustar().is_some()
&& entry.header().entry_type().is_pax_local_extensions()
{
if is_recognized_header && entry.header().entry_type().is_pax_local_extensions() {
if pax_extensions.is_some() {
return Err(other(
"two pax extensions entries describing \
Expand Down
4 changes: 2 additions & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,8 +1604,8 @@ pub fn bytes2path(bytes: Cow<[u8]>) -> io::Result<Cow<Path>> {
use std::ffi::{OsStr, OsString};

Ok(match bytes {
Cow::Borrowed(bytes) => Cow::Borrowed({ Path::new(OsStr::from_bytes(bytes)) }),
Cow::Owned(bytes) => Cow::Owned({ PathBuf::from(OsString::from_vec(bytes)) }),
Cow::Borrowed(bytes) => Cow::Borrowed(Path::new(OsStr::from_bytes(bytes))),
Cow::Owned(bytes) => Cow::Owned(PathBuf::from(OsString::from_vec(bytes))),
})
}

Expand Down
8 changes: 8 additions & 0 deletions tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,3 +1011,11 @@ fn tar_directory_containing_symlink_to_directory() {
ar.append_dir_all("symlinks", td.path()).unwrap();
ar.finish().unwrap();
}

#[test]
fn long_path() {
let td = t!(TempBuilder::new().prefix("tar-rs").tempdir());
let rdr = Cursor::new(tar!("7z_long_path.tar"));
let mut ar = Archive::new(rdr);
assert!(ar.unpack(td.path()).is_ok());
}
Binary file added tests/archives/7z_long_path.tar
Binary file not shown.

0 comments on commit 6969cc7

Please sign in to comment.