Skip to content
Merged
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cloudflare-zlib-sys"
version = "0.3.6"
version = "0.3.7"
edition = "2021"
authors = ["Vlad Krasnov <vlad@cloudflare.com>", "Kornel Lesiński <kornel@geekhood.net>", "Mark Adler <madler@alumni.caltech.edu>"]
categories = ["external-ffi-bindings", "compression"]
Expand All @@ -25,3 +25,6 @@ cc = "1.1"
[features]
# Obsolete
asm = []

[badges]
maintenance.status = "deprecated"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions gzwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 4 additions & 5 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1516,7 +1517,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)
Expand All @@ -1527,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;
Expand All @@ -1551,10 +1552,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;
Expand Down
4 changes: 4 additions & 0 deletions uncompr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down