From 83ad090e4d4a748d17c31166b54c4c2adc599ed5 Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 25 Feb 2026 16:30:23 +0000 Subject: [PATCH 1/7] Deprecate --- Cargo.toml | 5 ++++- README.md | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04f7e51f0..85dcbef68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cloudflare-zlib-sys" -version = "0.3.6" +version = "0.3.7" edition = "2021" authors = ["Vlad Krasnov ", "Kornel LesiƄski ", "Mark Adler "] categories = ["external-ffi-bindings", "compression"] @@ -25,3 +25,6 @@ cc = "1.1" [features] # Obsolete asm = [] + +[badges] +maintenance.status = "deprecated" diff --git a/README.md b/README.md index 7b1e6d6f8..b827a7605 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ This is a fork of zlib with performance improvements developed for use at Cloudflare. -This implementation only supports x86-64 with SSE 4.2+ and aarch64 with NEON & CRC. 32-bit CPUs are not supported at all. +## Deprecated -The API and ABI are compatible with the original zlib. +We're avoiding use of memory-unsafe languages, and don't plan any further development of this library. -This library is also available as a [Rust crate](https://lib.rs/crates/cloudflare-zlib). +We recommend switching to [zlib-rs](https://lib.rs/crates/zlib-rs) instead. From b72ca325be57c3b1b71c7f0b7d3223add3295e74 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Thu, 12 Oct 2017 19:34:51 -0700 Subject: [PATCH 2/7] Avoid undefined behaviors of memcpy() in gz*printf(). --- gzwrite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gzwrite.c b/gzwrite.c index e2d4edce4..391d2f751 100644 --- a/gzwrite.c +++ b/gzwrite.c @@ -372,8 +372,8 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) left = strm->avail_in - state->size; strm->avail_in = state->size; if (gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - memcpy(state->in, state->in + state->size, left); + return state->err; + memmove(state->in, state->in + state->size, left); strm->next_in = state->in; strm->avail_in = left; } @@ -470,8 +470,8 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, left = strm->avail_in - state->size; strm->avail_in = state->size; if (gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - memcpy(state->in, state->in + state->size, left); + return state->err; + memmove(state->in, state->in + state->size, left); strm->next_in = state->in; strm->avail_in = left; } From 73d93adbf1fb0e1f18b53f683eea2550f556ccda Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Tue, 17 Apr 2018 22:44:41 -0700 Subject: [PATCH 3/7] Assure that the number of bits for deflatePrime() is valid. --- deflate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deflate.c b/deflate.c index fb2d5f183..58f1fb67a 100644 --- a/deflate.c +++ b/deflate.c @@ -474,6 +474,8 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; + if (bits < 0 || bits > 16) + return Z_BUF_ERROR; if ((uint8_t *)(s->sym_buf) < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; do { From 716ff6238b1194e1caa8e1a979f5f1dfde6583da Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Wed, 24 Jan 2024 14:46:09 -0800 Subject: [PATCH 4/7] Update copyright years in LICENSE file. --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ab8ee6f71..b517acd57 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ Copyright notice: - (C) 1995-2022 Jean-loup Gailly and Mark Adler + (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages From 0a99640f4482ce80fb3f9a38ccaeae0ea93059c2 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 21 Dec 2025 18:34:14 -0800 Subject: [PATCH 5/7] Copy only the initialized window contents in inflateCopy. To avoid the propagation and possible disclosure of uninitialized memory contents. --- inflate.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/inflate.c b/inflate.c index af3b2a7ba..e9f987bcb 100644 --- a/inflate.c +++ b/inflate.c @@ -1516,7 +1516,6 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; - unsigned wsize; /* check input */ if (inflateStateCheck(source) || dest == Z_NULL) @@ -1551,10 +1550,8 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { copy->distcode = copy->codes + (state->distcode - state->codes); } copy->next = copy->codes + (state->next - state->codes); - if (window != Z_NULL) { - wsize = 1U << state->wbits; - zmemcpy(window, state->window, wsize); - } + if (window != Z_NULL) + zmemcpy(window, state->window, state->whave); copy->window = window; dest->state = (struct internal_state FAR *)copy; return Z_OK; From a731d5c74c2a4738cf42b94de80ba8261fa351e3 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 11 Jan 2026 09:46:29 -0800 Subject: [PATCH 6/7] Zero inflate state on allocation. To further guard against the propagation of uninitialized memory. --- inflate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inflate.c b/inflate.c index e9f987bcb..1a9a7518f 100644 --- a/inflate.c +++ b/inflate.c @@ -219,6 +219,7 @@ int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, state = (struct inflate_state FAR *) ZALLOC(strm, 1, sizeof(struct inflate_state)); if (state == Z_NULL) return Z_MEM_ERROR; + zmemzero(state, sizeof(struct inflate_state)); Tracev((stderr, "inflate: allocated\n")); strm->state = (struct internal_state FAR *)state; state->strm = strm; @@ -1526,6 +1527,7 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { copy = (struct inflate_state FAR *) ZALLOC(source, 1, sizeof(struct inflate_state)); if (copy == Z_NULL) return Z_MEM_ERROR; + zmemzero(copy, sizeof(struct inflate_state)); window = Z_NULL; if (state->window != Z_NULL) { unsigned wsize_padded = 1U << state->wbits; From ca36d277e67186ceee9628300924f5b662c77881 Mon Sep 17 00:00:00 2001 From: gaoshutao <1779227906@qq.com> Date: Mon, 25 Aug 2025 15:38:00 +0800 Subject: [PATCH 7/7] Check for invalid NULL pointer inputs to zlib operations. --- compress.c | 4 ++++ gzlib.c | 2 +- uncompr.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compress.c b/compress.c index f43bacf7a..be1874ddf 100644 --- a/compress.c +++ b/compress.c @@ -26,6 +26,10 @@ int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, const uInt max = (uInt)-1; uLong left; + if ((sourceLen > 0 && source == NULL) || + destLen == NULL || (*destLen > 0 && dest == NULL)) + return Z_STREAM_ERROR; + left = *destLen; *destLen = 0; diff --git a/gzlib.c b/gzlib.c index 487862cad..af1b210cd 100644 --- a/gzlib.c +++ b/gzlib.c @@ -99,7 +99,7 @@ static gzFile gz_open(const void *path, int fd, const char *mode) #endif /* check input */ - if (path == NULL) + if (path == NULL || mode == NULL) return NULL; /* allocate gzFile structure to return */ diff --git a/uncompr.c b/uncompr.c index 5e256663b..27083ea26 100644 --- a/uncompr.c +++ b/uncompr.c @@ -32,6 +32,10 @@ int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong len, left; Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ + if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) || + destLen == NULL || (*destLen > 0 && dest == NULL)) + return Z_STREAM_ERROR; + len = *sourceLen; if (*destLen) { left = *destLen;