-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9384dde
commit 8fff05d
Showing
3 changed files
with
81 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ pub use sync::*; | |
mod error; | ||
pub mod stream; | ||
mod sync; | ||
mod tar; | ||
mod vendor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::path::{Component, Path, PathBuf}; | ||
|
||
/// Determine the path at which the given tar entry will be unpacked, when unpacking into `dst`. | ||
/// | ||
/// See: <https://github.com/vorot93/tokio-tar/blob/87338a76092330bc6fe60de95d83eae5597332e1/src/entry.rs#L418> | ||
#[cfg_attr(not(target_os = "unix"), allow(dead_code))] | ||
pub(crate) fn unpacked_at(dst: &Path, entry: &Path) -> Option<PathBuf> { | ||
let mut file_dst = dst.to_path_buf(); | ||
{ | ||
for part in entry.components() { | ||
match part { | ||
// Leading '/' characters, root paths, and '.' | ||
// components are just ignored and treated as "empty | ||
// components" | ||
Component::Prefix(..) | Component::RootDir | Component::CurDir => { | ||
continue; | ||
} | ||
|
||
// If any part of the filename is '..', then skip over | ||
// unpacking the file to prevent directory traversal | ||
// security issues. See, e.g.: CVE-2001-1267, | ||
// CVE-2002-0399, CVE-2005-1918, CVE-2007-4131 | ||
Component::ParentDir => return None, | ||
|
||
Component::Normal(part) => file_dst.push(part), | ||
} | ||
} | ||
} | ||
|
||
// Skip cases where only slashes or '.' parts were seen, because | ||
// this is effectively an empty filename. | ||
if *dst == *file_dst { | ||
return None; | ||
} | ||
|
||
// Skip entries without a parent (i.e. outside of FS root) | ||
file_dst.parent()?; | ||
|
||
Some(file_dst) | ||
} |