Gentoo Archives: gentoo-commits

From: Sam James <sam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/zlib/files/, sys-libs/zlib/
Date: Thu, 31 Mar 2022 00:21:06
Message-Id: 1648685948.37f4162df7f95c4c101ac94792d50894560b994a.sam@gentoo
1 commit: 37f4162df7f95c4c101ac94792d50894560b994a
2 Author: Sam James <sam <AT> gentoo <DOT> org>
3 AuthorDate: Thu Mar 31 00:18:55 2022 +0000
4 Commit: Sam James <sam <AT> gentoo <DOT> org>
5 CommitDate: Thu Mar 31 00:19:08 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=37f4162d
7
8 sys-libs/zlib: backport CRC fix
9
10 Would return bad results on bad input.
11
12 Closes: https://bugs.gentoo.org/836370
13 Signed-off-by: Sam James <sam <AT> gentoo.org>
14
15 .../zlib/files/zlib-1.2.12-CRC-buggy-input.patch | 50 ++++++
16 .../zlib-1.2.12-use-LDFLAGS-in-configure.patch | 71 ++++++++
17 sys-libs/zlib/zlib-1.2.12-r2.ebuild | 194 +++++++++++++++++++++
18 3 files changed, 315 insertions(+)
19
20 diff --git a/sys-libs/zlib/files/zlib-1.2.12-CRC-buggy-input.patch b/sys-libs/zlib/files/zlib-1.2.12-CRC-buggy-input.patch
21 new file mode 100644
22 index 000000000000..083634929bbe
23 --- /dev/null
24 +++ b/sys-libs/zlib/files/zlib-1.2.12-CRC-buggy-input.patch
25 @@ -0,0 +1,50 @@
26 +https://github.com/madler/zlib/commit/ec3df00224d4b396e2ac6586ab5d25f673caa4c2
27 +https://github.com/madler/zlib/issues/613
28 +https://bugs.gentoo.org/836370
29 +
30 +From ec3df00224d4b396e2ac6586ab5d25f673caa4c2 Mon Sep 17 00:00:00 2001
31 +From: Mark Adler <madler@××××××××××××××.edu>
32 +Date: Wed, 30 Mar 2022 11:14:53 -0700
33 +Subject: [PATCH] Correct incorrect inputs provided to the CRC functions.
34 +
35 +The previous releases of zlib were not sensitive to incorrect CRC
36 +inputs with bits set above the low 32. This commit restores that
37 +behavior, so that applications with such bugs will continue to
38 +operate as before.
39 +--- a/crc32.c
40 ++++ b/crc32.c
41 +@@ -630,7 +630,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
42 + #endif /* DYNAMIC_CRC_TABLE */
43 +
44 + /* Pre-condition the CRC */
45 +- crc ^= 0xffffffff;
46 ++ crc = (~crc) & 0xffffffff;
47 +
48 + /* Compute the CRC up to a word boundary. */
49 + while (len && ((z_size_t)buf & 7) != 0) {
50 +@@ -749,7 +749,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
51 + #endif /* DYNAMIC_CRC_TABLE */
52 +
53 + /* Pre-condition the CRC */
54 +- crc ^= 0xffffffff;
55 ++ crc = (~crc) & 0xffffffff;
56 +
57 + #ifdef W
58 +
59 +@@ -1077,7 +1077,7 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
60 + #ifdef DYNAMIC_CRC_TABLE
61 + once(&made, make_crc_table);
62 + #endif /* DYNAMIC_CRC_TABLE */
63 +- return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
64 ++ return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
65 + }
66 +
67 + /* ========================================================================= */
68 +@@ -1112,5 +1112,5 @@ uLong crc32_combine_op(crc1, crc2, op)
69 + uLong crc2;
70 + uLong op;
71 + {
72 +- return multmodp(op, crc1) ^ crc2;
73 ++ return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
74 + }
75 +
76
77 diff --git a/sys-libs/zlib/files/zlib-1.2.12-use-LDFLAGS-in-configure.patch b/sys-libs/zlib/files/zlib-1.2.12-use-LDFLAGS-in-configure.patch
78 new file mode 100644
79 index 000000000000..752a473eac22
80 --- /dev/null
81 +++ b/sys-libs/zlib/files/zlib-1.2.12-use-LDFLAGS-in-configure.patch
82 @@ -0,0 +1,71 @@
83 +https://github.com/madler/zlib/pull/599
84 +
85 +From 37c9730ba474d274f4cc6a974943eef95087b9f6 Mon Sep 17 00:00:00 2001
86 +From: Khem Raj <raj.khem@×××××.com>
87 +Date: Tue, 8 Mar 2022 22:38:47 -0800
88 +Subject: [PATCH] configure: Pass LDFLAGS to link tests
89 +
90 +LDFLAGS can contain critical flags without which linking wont succeed
91 +therefore ensure that all configure tests involving link time checks are
92 +using LDFLAGS on compiler commandline along with CFLAGS to ensure the
93 +tests perform correctly. Without this some tests may fail resulting in
94 +wrong confgure result, ending in miscompiling the package
95 +
96 +Signed-off-by: Khem Raj <raj.khem@×××××.com>
97 +--- a/configure
98 ++++ b/configure
99 +@@ -410,7 +410,7 @@ if test $shared -eq 1; then
100 + echo Checking for shared library support... | tee -a configure.log
101 + # we must test in two steps (cc then ld), required at least on SunOS 4.x
102 + if try $CC -w -c $SFLAGS $test.c &&
103 +- try $LDSHARED $SFLAGS -o $test$shared_ext $test.o; then
104 ++ try $LDSHARED $SFLAGS $LDFLAGS -o $test$shared_ext $test.o; then
105 + echo Building shared library $SHAREDLIBV with $CC. | tee -a configure.log
106 + elif test -z "$old_cc" -a -z "$old_cflags"; then
107 + echo No shared library support. | tee -a configure.log
108 +@@ -492,7 +492,7 @@ int main(void) {
109 + }
110 + EOF
111 + fi
112 +- if try $CC $CFLAGS -o $test $test.c; then
113 ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then
114 + sizet=`./$test`
115 + echo "Checking for a pointer-size integer type..." $sizet"." | tee -a configure.log
116 + else
117 +@@ -530,7 +530,7 @@ int main(void) {
118 + return 0;
119 + }
120 + EOF
121 +- if try $CC $CFLAGS -o $test $test.c; then
122 ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then
123 + echo "Checking for fseeko... Yes." | tee -a configure.log
124 + else
125 + CFLAGS="${CFLAGS} -DNO_FSEEKO"
126 +@@ -547,7 +547,7 @@ cat > $test.c <<EOF
127 + #include <errno.h>
128 + int main() { return strlen(strerror(errno)); }
129 + EOF
130 +-if try $CC $CFLAGS -o $test $test.c; then
131 ++if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then
132 + echo "Checking for strerror... Yes." | tee -a configure.log
133 + else
134 + CFLAGS="${CFLAGS} -DNO_STRERROR"
135 +@@ -654,7 +654,7 @@ int main()
136 + return (mytest("Hello%d\n", 1));
137 + }
138 + EOF
139 +- if try $CC $CFLAGS -o $test $test.c; then
140 ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then
141 + echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log
142 +
143 + echo >> configure.log
144 +@@ -744,7 +744,7 @@ int main()
145 + }
146 + EOF
147 +
148 +- if try $CC $CFLAGS -o $test $test.c; then
149 ++ if try $CC $CFLAGS $LDFLAGS -o $test $test.c; then
150 + echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log
151 +
152 + echo >> configure.log
153 +
154
155 diff --git a/sys-libs/zlib/zlib-1.2.12-r2.ebuild b/sys-libs/zlib/zlib-1.2.12-r2.ebuild
156 new file mode 100644
157 index 000000000000..6aa6f8503bc7
158 --- /dev/null
159 +++ b/sys-libs/zlib/zlib-1.2.12-r2.ebuild
160 @@ -0,0 +1,194 @@
161 +# Copyright 1999-2022 Gentoo Authors
162 +# Distributed under the terms of the GNU General Public License v2
163 +
164 +EAPI=7
165 +
166 +AUTOTOOLS_AUTO_DEPEND="no"
167 +VERIFY_SIG_OPENPGP_KEY_PATH="${BROOT}"/usr/share/openpgp-keys/madler.asc
168 +inherit autotools multilib-minimal usr-ldscript verify-sig
169 +
170 +CYGWINPATCHES=(
171 + "https://github.com/cygwinports/zlib/raw/22a3462cae33a82ad966ea0a7d6cbe8fc1368fec/1.2.11-gzopen_w.patch -> ${PN}-1.2.11-cygwin-gzopen_w.patch"
172 + "https://github.com/cygwinports/zlib/raw/22a3462cae33a82ad966ea0a7d6cbe8fc1368fec/1.2.7-minizip-cygwin.patch -> ${PN}-1.2.7-cygwin-minizip.patch"
173 +)
174 +
175 +DESCRIPTION="Standard (de)compression library"
176 +HOMEPAGE="https://zlib.net/"
177 +SRC_URI="https://zlib.net/${P}.tar.gz
178 + https://www.gzip.org/zlib/${P}.tar.gz
179 + https://www.zlib.net/current/beta/${P}.tar.gz
180 + verify-sig? ( https://zlib.net/${P}.tar.gz.asc )
181 + elibc_Cygwin? ( ${CYGWINPATCHES[*]} )"
182 +
183 +LICENSE="ZLIB"
184 +SLOT="0/1" # subslot = SONAME
185 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris ~x86-winnt"
186 +IUSE="minizip static-libs"
187 +
188 +RDEPEND="!sys-libs/zlib-ng[compat]"
189 +DEPEND="${RDEPEND}"
190 +BDEPEND="minizip? ( ${AUTOTOOLS_DEPEND} )
191 + verify-sig? ( sec-keys/openpgp-keys-madler )"
192 +
193 +PATCHES=(
194 + # Don't install unexpected & unused crypt.h header (which would clash with other pkgs)
195 + # Pending upstream. bug #658536
196 + "${FILESDIR}"/${PN}-1.2.11-minizip-drop-crypt-header.patch
197 +
198 + # Respect AR, RANLIB, NM during build. Pending upstream. bug #831628
199 + "${FILESDIR}"/${PN}-1.2.11-configure-fix-AR-RANLIB-NM-detection.patch
200 +
201 + # Respect LDFLAGS during configure tests. Pending upstream
202 + "${FILESDIR}"/${PN}-1.2.12-use-LDFLAGS-in-configure.patch
203 +
204 + # Fix broken CC logic
205 + "${FILESDIR}"/${P}-fix-CC-logic-in-configure.patch
206 +
207 + # Backport for Java (and others), bug #836370
208 + "${FILESDIR}"/${P}-CRC-buggy-input.patch
209 +)
210 +
211 +src_prepare() {
212 + default
213 +
214 + if use elibc_Cygwin ; then
215 + local p
216 + for p in "${CYGWINPATCHES[@]}" ; do
217 + # Strip out the "... -> " from the array
218 + eapply -p2 "${DISTDIR}/${p#*> }"
219 + done
220 + fi
221 +
222 + if use minizip ; then
223 + cd contrib/minizip || die
224 + eautoreconf
225 + fi
226 +
227 + case ${CHOST} in
228 + *-cygwin*)
229 + # Do not use _wopen, it's a mingw-only symbol
230 + sed -i -e '/define WIDECHAR/d' "${S}"/gzguts.h || die
231 +
232 + # zlib1.dll is the mingw name, need cygz.dll
233 + # cygz.dll is loaded by toolchain, put into subdir
234 + sed -i -e 's|zlib1.dll|win32/cygz.dll|' win32/Makefile.gcc || die
235 +
236 + ;;
237 + esac
238 +
239 + case ${CHOST} in
240 + *-mingw*|mingw*|*-cygwin*)
241 + # Uses preconfigured Makefile rather than configure script
242 + multilib_copy_sources
243 +
244 + ;;
245 + esac
246 +}
247 +
248 +echoit() { echo "$@"; "$@"; }
249 +
250 +multilib_src_configure() {
251 + case ${CHOST} in
252 + *-mingw*|mingw*|*-cygwin*)
253 + ;;
254 +
255 + *)
256 + # bug #347167
257 + local uname=$("${BROOT}"/usr/share/gnuconfig/config.sub "${CHOST}" | cut -d- -f3)
258 +
259 + local myconf=(
260 + --shared
261 + --prefix="${EPREFIX}/usr"
262 + --libdir="${EPREFIX}/usr/$(get_libdir)"
263 + ${uname:+--uname=${uname}}
264 + )
265 +
266 + # Not an autoconf script, so can't use econf
267 + echoit "${S}"/configure "${myconf[@]}" || die
268 +
269 + ;;
270 + esac
271 +
272 + if use minizip ; then
273 + local minizipdir="contrib/minizip"
274 + mkdir -p "${BUILD_DIR}/${minizipdir}" || die
275 +
276 + cd ${minizipdir} || die
277 + ECONF_SOURCE="${S}/${minizipdir}" econf $(use_enable static-libs static)
278 + fi
279 +}
280 +
281 +multilib_src_compile() {
282 + case ${CHOST} in
283 + *-mingw*|mingw*|*-cygwin*)
284 + emake -f win32/Makefile.gcc STRIP=true PREFIX=${CHOST}-
285 + sed \
286 + -e 's|@prefix@|'"${EPREFIX}"'/usr|g' \
287 + -e 's|@exec_prefix@|${prefix}|g' \
288 + -e 's|@libdir@|${exec_prefix}/'$(get_libdir)'|g' \
289 + -e 's|@sharedlibdir@|${exec_prefix}/'$(get_libdir)'|g' \
290 + -e 's|@includedir@|${prefix}/include|g' \
291 + -e 's|@VERSION@|'${PV}'|g' \
292 + zlib.pc.in > zlib.pc || die
293 + ;;
294 +
295 + *)
296 + emake
297 +
298 + ;;
299 + esac
300 +
301 + use minizip && emake -C contrib/minizip
302 +}
303 +
304 +sed_macros() {
305 + # Clean up namespace a little, bug #383179
306 + # We do it here so we only have to tweak 2 files
307 + sed -i -r 's:\<(O[FN])\>:_Z_\1:g' "$@" || die
308 +}
309 +
310 +multilib_src_install() {
311 + case ${CHOST} in
312 + *-mingw*|mingw*|*-cygwin*)
313 + emake -f win32/Makefile.gcc install \
314 + BINARY_PATH="${ED}/usr/bin" \
315 + LIBRARY_PATH="${ED}/usr/$(get_libdir)" \
316 + INCLUDE_PATH="${ED}/usr/include" \
317 + SHARED_MODE=1
318 +
319 + # Overwrites zlib.pc created from win32/Makefile.gcc, bug #620136
320 + insinto /usr/$(get_libdir)/pkgconfig
321 + doins zlib.pc
322 +
323 + ;;
324 +
325 + *)
326 + emake install DESTDIR="${D}" LDCONFIG=:
327 + gen_usr_ldscript -a z
328 +
329 + ;;
330 + esac
331 +
332 + sed_macros "${ED}"/usr/include/*.h
333 +
334 + if use minizip ; then
335 + emake -C contrib/minizip install DESTDIR="${D}"
336 + sed_macros "${ED}"/usr/include/minizip/*.h
337 + fi
338 +
339 + if use minizip; then
340 + # This might not exist if slibtool is used.
341 + # bug #816756
342 + rm -f "${ED}"/usr/$(get_libdir)/libminizip.la || die
343 + fi
344 +
345 + if ! use static-libs ; then
346 + # bug #419645
347 + rm "${ED}"/usr/$(get_libdir)/libz.a || die
348 + fi
349 +}
350 +
351 +multilib_src_install_all() {
352 + dodoc FAQ README ChangeLog doc/*.txt
353 + use minizip && dodoc contrib/minizip/*.txt
354 +}