Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unpackPhase: fail when tar extract would overwrite files #341678

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 4 additions & 12 deletions pkgs/data/misc/tzdata/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ stdenv.mkDerivation (finalAttrs: {
pname = "tzdata";
version = "2024a";

srcs = [
(fetchurl {
url = "https://data.iana.org/time-zones/releases/tzdata${finalAttrs.version}.tar.gz";
hash = "sha256-DQQ0RZrL0gWaeo2h8zBKhKhlkfbtacYkj/+lArbt/+M=";
})
(fetchurl {
url = "https://data.iana.org/time-zones/releases/tzcode${finalAttrs.version}.tar.gz";
hash = "sha256-gAcolK3/WkWPHRQ+FuTKHYsqEiycU5naSCy2jLpqH/g=";
})
];

sourceRoot = ".";
src = (fetchurl {
url = "https://data.iana.org/time-zones/releases/tzdb-${finalAttrs.version}.tar.lz";
hash = "sha256-URr2tGf0Cx7JrDaE0XAXk69HDz4p3fuXuCvkOOhgGno=";
});

patches = lib.optionals stdenv.hostPlatform.isWindows [
./0001-Add-exe-extension-for-MS-Windows-binaries.patch
Expand Down
10 changes: 7 additions & 3 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ _defaultUnpack() {
else

case "$fn" in
*.tar.xz | *.tar.lzma | *.txz)
*.tar.xz | *.tar.lz | *.tar.lzma | *.txz)
# Don't rely on tar knowing about .xz.
# Additionally, we have multiple different xz binaries with different feature sets in different
# stages. The XZ_OPT env var is only used by the full "XZ utils" implementation, which supports
Expand All @@ -1219,12 +1219,16 @@ _defaultUnpack() {
# disregard the error code from the xz invocation. Otherwise,
# it can happen that tar exits earlier, causing xz to fail
# from a SIGPIPE.
(XZ_OPT="--threads=$NIX_BUILD_CORES" xz -d < "$fn"; true) | tar xf - --mode=+w --warning=no-timestamp
#
# keep-old-files will cause tar to fail if it would overwrite files with the same name but
# different cases on case insensitive filesystems (darwin) preventing cross-platform
# package hash mismatches
(XZ_OPT="--threads=$NIX_BUILD_CORES" xz -d < "$fn"; true) | tar xf - --keep-old-files --mode=+w --warning=no-timestamp
;;
*.tar | *.tar.* | *.tgz | *.tbz2 | *.tbz)
# GNU tar can automatically select the decompression method
# (info "(tar) gzip").
tar xf "$fn" --mode=+w --warning=no-timestamp
tar xf "$fn" --keep-old-files --mode=+w --warning=no-timestamp
;;
*)
return 1
Expand Down