Skip to content

Commit

Permalink
Don't panic on members with empty filenames
Browse files Browse the repository at this point in the history
Closes #23
  • Loading branch information
alexcrichton committed May 12, 2015
1 parent 5830d58 commit 9e1b9b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl<R: Read> Archive<R> {
let bytes = file.filename_bytes().iter().map(|&b| {
if b == b'\\' {b'/'} else {b}
}).collect::<Vec<_>>();
if bytes.len() == 0 {
return Err(io::Error::new(io::ErrorKind::Other,
"empty file name in tarball"))
}
let is_directory = bytes[bytes.len() - 1] == b'/';
let mut dst = into.to_path_buf();
for part in bytes.split(|x| *x == b'/') {
Expand Down Expand Up @@ -794,8 +798,7 @@ mod tests {
}

#[test]
fn octal_spaces()
{
fn octal_spaces() {
let rdr = Cursor::new(&include_bytes!("tests/spaces.tar")[..]);
let ar = Archive::new(rdr);

Expand All @@ -807,4 +810,13 @@ mod tests {
assert_eq!(file.mtime().unwrap(), 0o12440016664);
assert_eq!(file.header.cksum().unwrap(), 0o4253);
}

#[test]
fn empty_filename()
{
let td = t!(TempDir::new("tar-rs"));
let rdr = Cursor::new(&include_bytes!("tests/empty_filename.tar")[..]);
let mut ar = Archive::new(rdr);
assert!(ar.unpack(td.path()).is_err());
}
}
Binary file added src/tests/empty_filename.tar
Binary file not shown.

0 comments on commit 9e1b9b4

Please sign in to comment.