···11+From ec3df00224d4b396e2ac6586ab5d25f673caa4c2 Mon Sep 17 00:00:00 2001
22+From: Mark Adler <madler@alumni.caltech.edu>
33+Date: Wed, 30 Mar 2022 11:14:53 -0700
44+Subject: [PATCH] Correct incorrect inputs provided to the CRC functions.
55+66+The previous releases of zlib were not sensitive to incorrect CRC
77+inputs with bits set above the low 32. This commit restores that
88+behavior, so that applications with such bugs will continue to
99+operate as before.
1010+---
1111+ crc32.c | 8 ++++----
1212+ 1 file changed, 4 insertions(+), 4 deletions(-)
1313+1414+diff --git a/crc32.c b/crc32.c
1515+index a1bdce5c2..451887bc7 100644
1616+--- a/crc32.c
1717++++ b/crc32.c
1818+@@ -630,7 +630,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
1919+ #endif /* DYNAMIC_CRC_TABLE */
2020+2121+ /* Pre-condition the CRC */
2222+- crc ^= 0xffffffff;
2323++ crc = (~crc) & 0xffffffff;
2424+2525+ /* Compute the CRC up to a word boundary. */
2626+ while (len && ((z_size_t)buf & 7) != 0) {
2727+@@ -749,7 +749,7 @@ unsigned long ZEXPORT crc32_z(crc, buf, len)
2828+ #endif /* DYNAMIC_CRC_TABLE */
2929+3030+ /* Pre-condition the CRC */
3131+- crc ^= 0xffffffff;
3232++ crc = (~crc) & 0xffffffff;
3333+3434+ #ifdef W
3535+3636+@@ -1077,7 +1077,7 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
3737+ #ifdef DYNAMIC_CRC_TABLE
3838+ once(&made, make_crc_table);
3939+ #endif /* DYNAMIC_CRC_TABLE */
4040+- return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;
4141++ return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
4242+ }
4343+4444+ /* ========================================================================= */
4545+@@ -1112,5 +1112,5 @@ uLong crc32_combine_op(crc1, crc2, op)
4646+ uLong crc2;
4747+ uLong op;
4848+ {
4949+- return multmodp(op, crc1) ^ crc2;
5050++ return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
5151+ }
+6
pkgs/development/libraries/zlib/default.nix
···42424343 patches = [
4444 ./fix-configure-issue-cross.patch
4545+ # Starting zlib 1.2.12, zlib is stricter to incorrect CRC inputs
4646+ # with bits set above the low 32.
4747+ # see https://github.com/madler/zlib/issues/618
4848+ # TODO: remove the patch if upstream releases https://github.com/madler/zlib/commit/ec3df00224d4b396e2ac6586ab5d25f673caa4c2
4949+ # see https://github.com/NixOS/nixpkgs/issues/170539 for history.
5050+ ./comprehensive-crc-validation-for-wrong-implementations.patch
4551 ];
46524753 strictDeps = true;