Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ static DownloadTarballResult downloadTarball_(
// it is not in fact a tarball.
if (url.scheme == "file") {
std::filesystem::path localPath = renderUrlPathEnsureLegal(url.path);
if (!localPath.is_absolute()) {
throw Error(
"tarball '%s' must use an absolute path. "
"The 'file' scheme does not support relative paths.",
url);
}
if (!exists(localPath)) {
throw Error("tarball '%s' does not exist.", localPath);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/functional/lang/eval-fail-fetchTree-relative-path.err.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error:
… while calling the 'fetchTree' builtin
at /pwd/lang/eval-fail-fetchTree-relative-path.nix:1:1:
1| builtins.fetchTree "file:./relative-path.tar.gz"
| ^
2|

… while fetching the input 'file:./relative-path.tar.gz'

error: tarball 'file:./relative-path.tar.gz' must use an absolute path. The 'file' scheme does not support relative paths.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builtins.fetchTree "file:./relative-path.tar.gz"
Loading