Skip to content

Commit 5c7f73a

Browse files
committed
build: Don't silently corrupt non-utf8 paths in cargo directives
Using `.display()` to convert a path to a string is dangerous when that path is ever meant to be interpreted again. If the original string contained invalid UTF-8, the `.display()` path will be different than the original. Instead of silently allowing for this, error out on non-utf8 paths. This isn't perfect, but at least won't lead to hard-to-explain behavior.
1 parent 16e9169 commit 5c7f73a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ impl InputFinder {
195195
}
196196
}
197197

198-
cargo_directives.push(format!("cargo::rerun-if-changed={}", path.display()));
198+
cargo_directives.push(format!(
199+
"cargo::rerun-if-changed={}",
200+
path.to_str().ok_or(anyhow::anyhow!(
201+
"file with non UTF-8 name in `{}`",
202+
path.display()
203+
))?
204+
));
199205

200206
Ok(())
201207
}

0 commit comments

Comments
 (0)