summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/zi/zip/package.nix
blob: e67be89c2a9bd32200ff32f6fa9cc001733552e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
  lib,
  stdenv,
  fetchurl,
  enableNLS ? false,
  libnatspec ? null,
  libiconv,
  fetchpatch,
  fetchDebianPatch,
}:

assert enableNLS -> libnatspec != null;

stdenv.mkDerivation (finalAttrs: {
  pname = "zip";
  version = "3.0";

  src = fetchurl {
    urls = [
      "ftp://ftp.info-zip.org/pub/infozip/src/zip${
        lib.replaceStrings [ "." ] [ "" ] finalAttrs.version
      }.tgz"
      "https://src.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz"
    ];
    sha256 = "0sb3h3067pzf3a7mlxn1hikpcjrsvycjcnj9hl9b1c3ykcgvps7h";
  };

  postPatch = ''
    substituteInPlace unix/Makefile --replace 'CC = cc' ""
    substituteInPlace unix/configure --replace-fail "O3" "O2"
  '';

  makefile = "unix/Makefile";
  buildFlags = if stdenv.hostPlatform.isCygwin then [ "cygwin" ] else [ "generic" ];
  installFlags = [
    "prefix=${placeholder "out"}"
    "INSTALL=cp"
  ];

  patches = [
    # Implicit declaration of `closedir` and `opendir` cause dirent detection to fail with clang 16.
    ./fix-implicit-declarations.patch
    # Fixes forward declaration errors with timezone.c
    ./fix-time.h-not-included.patch
    # Without this patch, we get a runtime failures with GCC 14 when building OpenJDK 8:
    #
    #     zip I/O error: No such file or directory
    #     zip error: Could not create output file (was replacing the original zip file)
    #     make[2]: *** [CreateJars.gmk:659: /build/source/build/linux-x86_64-normal-server-release/images/src.zip] Error 1
    (fetchDebianPatch {
      inherit (finalAttrs) pname version;
      debianRevision = "16";
      patch = "fix-build-with-gcc-14.patch";
      hash = "sha256-C966AdPV5E44cJ1L28iFvmXq3frjNiW6PoHiOOusS04=";
    })
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-pic.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-OXgC9KqiOpH/o/bSabt3LqtoT/xifqfkvpLLPfPz+1c=";
    })
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-no-crypt.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-9bwV+uKST828PcRVbICs8xwz9jcIPk26gxLBbiEeta4=";
    })
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-format-security.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-YmGKivZ0iFCFmPjVYuOv9D8Y0xG2QnWOpas8gMgoQ3M=";
    })
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-exec-stack.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-akJFY+zGijPWCwaAL/xxCN4wQpVFBHkLMo2HowrSn/M=";
    })
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-build.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-MiupD7W+sxiRTsB5viKAiI4QeqtZC6VttfJktdt1ucI=";
    })
    # Buffer overflow on Unicode characters in path names
    # https://bugzilla.redhat.com/show_bug.cgi?id=2165653
    # (included among other changes below)
    (fetchpatch {
      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/zip/files/zip-3.0-zipnote-freeze.patch?id=d37d095fc7a2a9e4a8e904a7bf0f597fe99df85a";
      hash = "sha256-EVr7YS3IytnCRjAYUlkg05GA/kaAY9NRFG7uDt0QLAY=";
    })
    # Fix buffer overflow (CVE-2018-13410).
    # See: https://seclists.org/fulldisclosure/2018/Jul/24
    (fetchDebianPatch {
      inherit (finalAttrs) pname version;
      debianRevision = "16";
      patch = "buffer-overflow-cve-2018-13410.patch";
      hash = "sha256-Hgy0yrBuSX2XWN1PNASQbjiXfyzSScwHQ+o0fv6Sgs4=";
    })
    # Command injection in zip -T for specially crafted file
    # names. See: https://seclists.org/oss-sec/2026/q3/494
    (fetchDebianPatch {
      inherit (finalAttrs) pname version;
      debianRevision = "16";
      patch = "fix-command-injection.patch";
      hash = "sha256-cfE98l98KkPfDS5KT/DB2bqFNPTbHBKyJ7W2+iKgaGI=";
    })
  ]
  ++ lib.optionals (enableNLS && !stdenv.hostPlatform.isCygwin) [ ./natspec-gentoo.patch.bz2 ];

  buildInputs =
    lib.optional enableNLS libnatspec ++ lib.optional stdenv.hostPlatform.isCygwin libiconv;

  meta = {
    description = "Compressor/archiver for creating and modifying zipfiles";
    homepage = "http://www.info-zip.org";
    license = lib.licenses.bsdOriginal;
    platforms = lib.platforms.all;
    maintainers = with lib.maintainers; [ RossComputerGuy ];
    mainProgram = "zip";
  };
})