Skip to content

Commit cadbb52

Browse files
authored
If a file path references a parent directory, transform it to ensure we keep inside the OUT_DIR (#786)
1 parent 9e50fb8 commit cadbb52

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,10 @@ impl Build {
10371037

10381038
let mut objects = Vec::new();
10391039
for file in self.files.iter() {
1040-
let obj = if file.has_root() {
1041-
// If `file` is an absolute path, prefix the `basename`
1042-
// with the `dirname`'s hash to ensure name uniqueness.
1040+
let obj = if file.has_root() || file.components().any(|x| x == Component::ParentDir) {
1041+
// If `file` is an absolute path or might not be usable directly as a suffix due to
1042+
// using "..", use the `basename` prefixed with the `dirname`'s hash to ensure name
1043+
// uniqueness.
10431044
let basename = file
10441045
.file_name()
10451046
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "file_name() failure"))?

0 commit comments

Comments
 (0)