diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index b1ebd749df6..94e232fa70c 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -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); } diff --git a/tests/functional/lang/eval-fail-fetchTree-relative-path.err.exp b/tests/functional/lang/eval-fail-fetchTree-relative-path.err.exp new file mode 100644 index 00000000000..863f143d19a --- /dev/null +++ b/tests/functional/lang/eval-fail-fetchTree-relative-path.err.exp @@ -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. diff --git a/tests/functional/lang/eval-fail-fetchTree-relative-path.nix b/tests/functional/lang/eval-fail-fetchTree-relative-path.nix new file mode 100644 index 00000000000..38826758134 --- /dev/null +++ b/tests/functional/lang/eval-fail-fetchTree-relative-path.nix @@ -0,0 +1 @@ +builtins.fetchTree "file:./relative-path.tar.gz"