packages feed

zlib-clib 1.3.2 → 1.4

raw patch · 16 files changed

+222/−100 lines, 16 files

Files

cbits/compress.c view
@@ -28,8 +28,8 @@     const uInt max = (uInt)-1;     z_size_t left; -    if ((sourceLen > 0 && source == NULL) ||-        destLen == NULL || (*destLen > 0 && dest == NULL))+    if ((sourceLen > 0 && source == Z_NULL) ||+        destLen == Z_NULL || (*destLen > 0 && dest == Z_NULL))         return Z_STREAM_ERROR;      left = *destLen;
cbits/crc32.c view
@@ -686,7 +686,7 @@ #endif              /* Initialize the CRC for each braid. */-            crc0 = crc;+            crc0 = (z_crc_t)crc; #if N > 1             crc1 = 0; #if N > 2
cbits/deflate.c view
@@ -52,7 +52,7 @@ #include "deflate.h"  const char deflate_copyright[] =-   " deflate 1.3.2 Copyright 1995-2026 Jean-loup Gailly and Mark Adler ";+   " deflate 1.4 Copyright 1995-2026 Jean-loup Gailly and Mark Adler "; /*   If you use the zlib library in a product, an acknowledgment is welcome   in the documentation of your product. If for some reason you cannot@@ -445,7 +445,6 @@     s->status = INIT_STATE;     /* to pass state test in deflateReset() */      s->wrap = wrap;-    s->gzhead = Z_NULL;     s->w_bits = (uInt)windowBits;     s->w_size = 1 << s->w_bits;     s->w_mask = s->w_size - 1;@@ -568,7 +567,8 @@         return Z_STREAM_ERROR;     s = strm->state;     wrap = s->wrap;-    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)+    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead ||+        (wrap == 0 && (long)s->strstart != s->block_start))         return Z_STREAM_ERROR;      /* when using zlib wrappers, compute Adler-32 for provided dictionary */@@ -671,8 +671,21 @@         adler32(0L, Z_NULL, 0);     s->last_flush = -2; -    _tr_init(s);+    s->gzhead = Z_NULL; +    {+        /* Retain the hash work done for level 0. */+        uInt matches = s->level == 0 ? s->matches : 0;+        _tr_init(s);+        s->matches = matches;+    }++    /* Keep the window and the hash, but drop what was left unfinished */+    s->block_start = (long)s->strstart;+    s->lookahead = 0;+    s->match_length = s->prev_length = MIN_MATCH-1;+    s->match_available = 0;+     return Z_OK; } @@ -683,6 +696,7 @@     s->window_size = (ulg)2L*s->w_size;      CLEAR_HASH(s);+    s->matches = 0;             /* the hash is clear */      /* Set the default configuration parameters:      */@@ -745,18 +759,23 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {     deflate_state *s;     int put;+    int need;      if (deflateStateCheck(strm)) return Z_STREAM_ERROR;     s = strm->state;-#ifdef LIT_MEM-    if (bits < 0 || bits > 16 ||-        (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3))+    if (bits < 0 || bits > 16)         return Z_BUF_ERROR;-#else-    if (bits < 0 || bits > 16 ||-        s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))+    if (s->pending_out != s->pending_buf) {+        /* move partially flushed pending output to buffer start */+        Bytef *to = s->pending_buf, *from = s->pending_out;+        ulg n = s->pending;+        while (n--)+            *to++ = *from++;+        s->pending_out = s->pending_buf;+    }+    need = (s->bi_valid + bits) >> 3;+    if (s->pending_buf_size - s->pending < (ulg)need)         return Z_BUF_ERROR;-#endif     do {         put = Buf_size - s->bi_valid;         if (put > bits)@@ -1316,39 +1335,49 @@  */ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K-    (void)dest;     (void)source;+    if (dest != Z_NULL)+        dest->state = Z_NULL;     return Z_STREAM_ERROR; #else     deflate_state *ds;     deflate_state *ss; --    if (deflateStateCheck(source) || dest == Z_NULL) {+    if (dest == Z_NULL)         return Z_STREAM_ERROR;+    if (deflateStateCheck(source)) {+        dest->state = Z_NULL;+        return Z_STREAM_ERROR;     }      ss = source->state; -    zmemcpy(dest, source, sizeof(z_stream));--    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));-    if (ds == Z_NULL) return Z_MEM_ERROR;-    zmemzero(ds, sizeof(deflate_state));-    dest->state = (struct internal_state FAR *) ds;+    ds = (deflate_state *) ZALLOC(source, 1, sizeof(deflate_state));+    if (ds == Z_NULL) {+        dest->state = Z_NULL;+        return Z_MEM_ERROR;+    }     zmemcpy(ds, ss, sizeof(deflate_state));-    ds->strm = dest;--    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));-    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));-    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));-    ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);-+    ds->window = (Bytef *) ZALLOC(source, ds->w_size, 2*sizeof(Byte));+    ds->prev   = (Posf *)  ZALLOC(source, ds->w_size, sizeof(Pos));+    ds->head   = (Posf *)  ZALLOC(source, ds->hash_size, sizeof(Pos));+    ds->pending_buf = (uchf *) ZALLOC(source, ds->lit_bufsize, LIT_BUFS);     if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||         ds->pending_buf == Z_NULL) {-        deflateEnd (dest);+        TRY_FREE(source, ds->pending_buf);+        TRY_FREE(source, ds->head);+        TRY_FREE(source, ds->prev);+        TRY_FREE(source, ds->window);+        ZFREE(source, ds);+        dest->state = Z_NULL;         return Z_MEM_ERROR;     }++    /* copy the stream and attach the new state */+    zmemcpy(dest, source, sizeof(z_stream));+    dest->state = (struct internal_state FAR *) ds;+    ds->strm = dest;+     /* following zmemcpy's do not work for 16-bit MSDOS */     zmemcpy(ds->window, ss->window, ss->high_water);     zmemcpy(ds->prev, ss->prev,@@ -1641,7 +1670,10 @@ /* Same but force premature exit if necessary. */ #define FLUSH_BLOCK(s, last) { \    FLUSH_BLOCK_ONLY(s, last); \-   if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \+   if (s->strm->avail_out == 0) { \+      if (!(last)) return need_more; \+      if (s->pending != 0 || s->wrap != 0) return finish_started; \+   } \ }  /* Maximum stored block length in deflate format (not including header). */@@ -1676,7 +1708,7 @@      * possible. If flushing, copy the remaining available input to next_out as      * stored blocks, if there is enough space.      */-    int last = 0;+    int last = 0, all;     unsigned len, left, have;     unsigned used = s->strm->avail_in;     do {@@ -1691,11 +1723,14 @@             /* maximum stored block length that will fit in avail_out: */         have = s->strm->avail_out - have;         left = (unsigned)(s->strstart - s->block_start);    /* window bytes */-        if (len > (ulg)left + s->strm->avail_in)+        if (left < len && s->strm->avail_in < len - left)             len = left + s->strm->avail_in;     /* limit len to the input */         if (len > have)             len = have;                         /* limit len to the output */ +        /* all is true if len is all of the available input */+        all = len >= left && len - left == s->strm->avail_in;+         /* If the stored block would be less than min_block in length, or if          * unable to copy all of the available input when flushing, then try          * copying to the window and the pending buffer instead. Also don't@@ -1703,13 +1738,13 @@          */         if (len < min_block && ((len == 0 && flush != Z_FINISH) ||                                 flush == Z_NO_FLUSH ||-                                len != left + s->strm->avail_in))+                                !all))             break;          /* Make a dummy stored block in pending to get the header bytes,          * including any pending bits. This also updates the debugging counts.          */-        last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;+        last = flush == Z_FINISH && all ? 1 : 0;         _tr_stored_block(s, (char *)0, 0L, last);          /* Replace the lengths in the dummy stored block with len. */@@ -2014,7 +2049,8 @@             uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;             /* Do not insert strings in hash table beyond this. */ -            check_match(s, s->strstart - 1, s->prev_match, (int)s->prev_length);+            check_match(s, s->strstart - 1, s->prev_match,+                        (int)s->prev_length);              _tr_tally_dist(s, s->strstart - 1 - s->prev_match,                            s->prev_length - MIN_MATCH, bflush);
cbits/gzguts.h view
@@ -92,8 +92,10 @@ #        define vsnprintf _vsnprintf #      endif #    endif-#  elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L-/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */+#  elif (!defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L) && \+        (!defined(__cplusplus) || __cplusplus < 201103L)+/* Otherwise if C89/90 (and not C++11 or later), assume no C99 snprintf() or+   vsnprintf() */ #    ifndef NO_snprintf #      define NO_snprintf #    endif@@ -128,14 +130,28 @@ #  include <windows.h> #  define zstrerror() gz_strwinerror((DWORD)GetLastError()) #else+#  include <errno.h> #  ifndef NO_STRERROR-#    include <errno.h> #    define zstrerror() strerror(errno) #  else #    define zstrerror() "stdio error (consult errno)" #  endif #endif +#ifdef EAGAIN+#  ifdef EWOULDBLOCK+#    define BLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)+#  else+#    define BLOCKED(e) ((e) == EAGAIN)+#  endif+#else+#  ifdef EWOULDBLOCK+#    define BLOCKED(e) ((e) == EWOULDBLOCK)+#  else+#    define BLOCKED(e) (0)+#  endif+#endif+ /* provide prototypes for these when building zlib without LFS */ #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0     ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);@@ -214,3 +230,10 @@    (possible z_off64_t types off_t, off64_t, and long are all signed) */ unsigned ZLIB_INTERNAL gz_intmax(void); #define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())++/* largest value representable in z_off64_t */+#ifndef CHAR_BIT+#  define CHAR_BIT 8+#endif+#define GZ_OFF_MAX \+    ((((z_off64_t)1 << (sizeof(z_off64_t) * CHAR_BIT - 2)) - 1) * 2 + 1)
cbits/infback.c view
@@ -423,8 +423,6 @@             /* use inflate_fast() if we have enough input and output */             if (have >= 6 && left >= 258) {                 RESTORE();-                if (state->whave < state->wsize)-                    state->whave = state->wsize - left;                 inflate_fast(strm, state->wsize);                 LOAD();                 break;
cbits/inflate.c view
@@ -127,6 +127,14 @@      if (inflateStateCheck(strm)) return Z_STREAM_ERROR;     state = (struct inflate_state FAR *)strm->state;+    if (state->wbits != state->reqbits) {+        if (state->window != Z_NULL) {+            ZFREE(strm, state->window);+            state->window = Z_NULL;+        }+        state->wbits = state->reqbits;+    }+    state->wrap = state->reqwrap;     state->wsize = 0;     state->whave = 0;     state->wnext = 0;@@ -165,8 +173,8 @@     }      /* update state and reset the rest of it */-    state->wrap = wrap;-    state->wbits = (unsigned)windowBits;+    state->reqwrap = state->wrap = wrap;+    state->reqbits = state->wbits = (unsigned)windowBits;     return inflateReset(strm); } @@ -537,13 +545,13 @@             }             DROPBITS(4);             len = BITS(4) + 8;-            if (state->wbits == 0)-                state->wbits = len;-            if (len > 15 || len > state->wbits) {+            if (len > 15 || (state->wbits != 0 && len > state->wbits)) {                 strm->msg = (z_const char *)"invalid window size";                 state->mode = BAD;                 break;             }+            if (state->wbits == 0)+                state->wbits = len;             state->dmax = 1U << len;             state->flags = 0;               /* indicate zlib header */             Tracev((stderr, "inflate:   zlib header ok\n"));@@ -700,6 +708,7 @@         case DICT:             if (state->havedict == 0) {                 RESTORE();+                strm->total_in += in - strm->avail_in;                 return Z_NEED_DICT;             }             strm->adler = state->check = adler32(0L, Z_NULL, 0);@@ -912,7 +921,7 @@             state->mode = LEN;                 /* fallthrough */         case LEN:-            if (have >= 6 && left >= 258) {+            if (have >= 6 && left >= 258 && bits < 8) {                 RESTORE();                 inflate_fast(strm, out);                 LOAD();@@ -1191,7 +1200,8 @@     int ret;      /* check state */-    if (inflateStateCheck(strm)) return Z_STREAM_ERROR;+    if (inflateStateCheck(strm) || dictionary == Z_NULL)+        return Z_STREAM_ERROR;     state = (struct inflate_state FAR *)strm->state;     if (state->wrap != 0 && state->mode != DICT)         return Z_STREAM_ERROR;@@ -1296,15 +1306,23 @@      /* return no joy or set up to restart inflate() on a new block */     if (state->have != 4) return Z_DATA_ERROR;-    if (state->flags == -1)-        state->wrap = 0;    /* if no header yet, treat as raw */-    else-        state->wrap &= ~4;  /* no point in computing a check value now */     flags = state->flags;     in = strm->total_in;  out = strm->total_out;     inflateReset(strm);     strm->total_in = in;  strm->total_out = out;     state->flags = flags;+    if (flags == -1)+        state->wrap = 0;    /* if no header yet, treat as raw */+    else+        state->wrap &= ~4;  /* no point in computing a check value now */+    if (state->wbits == 0) {+        /* we never got to see a header for the window size -- set to max */+        if (state->window != Z_NULL) {+            ZFREE(strm, state->window);+            state->window = Z_NULL;+        }+        state->wbits = 15;+    }     state->mode = TYPE;     return Z_OK; }@@ -1331,14 +1349,21 @@     unsigned char FAR *window;      /* check input */-    if (inflateStateCheck(source) || dest == Z_NULL)+    if (dest == Z_NULL)         return Z_STREAM_ERROR;+    if (inflateStateCheck(source)) {+        dest->state = Z_NULL;+        return Z_STREAM_ERROR;+    }     state = (struct inflate_state FAR *)source->state;      /* allocate space */     copy = (struct inflate_state FAR *)            ZALLOC(source, 1, sizeof(struct inflate_state));-    if (copy == Z_NULL) return Z_MEM_ERROR;+    if (copy == Z_NULL) {+        dest->state = Z_NULL;+        return Z_MEM_ERROR;+    }     zmemzero(copy, sizeof(struct inflate_state));     window = Z_NULL;     if (state->window != Z_NULL) {@@ -1346,6 +1371,7 @@                  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));         if (window == Z_NULL) {             ZFREE(source, copy);+            dest->state = Z_NULL;             return Z_MEM_ERROR;         }     }@@ -1391,6 +1417,10 @@         state->wrap |= 4;     else         state->wrap &= ~4;+    if (check && state->reqwrap)+        state->reqwrap |= 4;+    else+        state->reqwrap &= ~4;     return Z_OK; } 
cbits/inflate.h view
@@ -85,6 +85,7 @@     int last;                   /* true if processing last block */     int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip,                                    bit 2 true to validate check value */+    int reqwrap;                /* requested wrap */     int havedict;               /* true if dictionary provided */     int flags;                  /* gzip header method and flags, 0 if zlib, or                                    -1 if raw or no header yet */@@ -93,7 +94,8 @@     unsigned long total;        /* protected copy of output count */     gz_headerp head;            /* where to save gzip header information */         /* sliding window */-    unsigned wbits;             /* log base 2 of requested window size */+    unsigned reqbits;           /* requested log base 2 of window size */+    unsigned wbits;             /* current log base 2 of window size */     unsigned wsize;             /* window size or zero if not using window */     unsigned whave;             /* valid bytes in the window */     unsigned wnext;             /* window write index */
cbits/inftrees.c view
@@ -23,7 +23,7 @@ #define MAXBITS 15  const char inflate_copyright[] =-   " inflate 1.3.2 Copyright 1995-2026 Mark Adler ";+   " inflate 1.4 Copyright 1995-2026 Mark Adler "; /*   If you use the zlib library in a product, an acknowledgment is welcome   in the documentation of your product. If for some reason you cannot@@ -71,7 +71,7 @@         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};     static const unsigned short lext[31] = { /* Length codes 257..285 extra */         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,-        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 75};+        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 71, 77};     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
cbits/inftrees.h view
@@ -46,8 +46,14 @@    inflate_table() calls in inflate.c and infback.c.  If the root table size is    changed, then these maximum sizes would be need to be recalculated and    updated. */-#define ENOUGH_LENS 852-#define ENOUGH_DISTS 592+#ifndef PKZIP_BUG_WORKAROUND+#  define ENOUGH_LENS 852+#  define ENOUGH_DISTS 592+#else+/* That workaround permits 288 literal/length codes and 32 distance codes. */+#  define ENOUGH_LENS 854+#  define ENOUGH_DISTS 594+#endif #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)  /* Type of code to build for inflate_table() */
cbits/trees.c view
@@ -227,7 +227,7 @@         tree[n].Code = (ush)bi_reverse(next_code[len]++, len);          Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",-            n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));+            n, (isgraph(n & 0xff) ? n : ' '), len, tree[n].Code, next_code[len] - 1));     } } 
cbits/uncompr.c view
@@ -33,8 +33,8 @@     const uInt max = (uInt)-1;     z_size_t len, left; -    if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) ||-        destLen == NULL || (*destLen > 0 && dest == NULL))+    if (sourceLen == Z_NULL || (*sourceLen > 0 && source == Z_NULL) ||+        destLen == Z_NULL || (*destLen > 0 && dest == Z_NULL))         return Z_STREAM_ERROR;      len = *sourceLen;
cbits/zconf.h view
@@ -499,6 +499,10 @@  #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 #  define Z_LFS64+#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && \+      !defined(UNDER_CE) && (defined(__MINGW32__) || !defined(__GNUC__))+#  define Z_LFS64       /* native Windows has 64-bit file offsets */+#  define Z_WINLFS #endif  #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)@@ -516,7 +520,7 @@ #endif  #ifndef z_off_t-#  define z_off_t long long+#  define z_off_t long #endif  #if !defined(_WIN32) && defined(Z_LARGE64)@@ -529,6 +533,11 @@ #  define z_off64_t offset_t #else #  define z_off64_t z_off_t+#endif++#if defined(Z_WINLFS) && defined(Z_WANT64) && !defined(Z_SOLO)+#  undef z_off_t+#  define z_off_t z_off64_t #endif  /* MVS linker does not support external names larger than 8 bytes */
cbits/zlib.h view
@@ -1,5 +1,5 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library-  version 1.3.2, February 17th, 2026+  version 1.4, November 4th, 2026    Copyright (C) 1995-2026 Jean-loup Gailly and Mark Adler @@ -41,11 +41,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.3.2"-#define ZLIB_VERNUM 0x1320+#define ZLIB_VERSION "1.4"+#define ZLIB_VERNUM 0x1400 #define ZLIB_VER_MAJOR 1-#define ZLIB_VER_MINOR 3-#define ZLIB_VER_REVISION 2+#define ZLIB_VER_MINOR 4+#define ZLIB_VER_REVISION 0 #define ZLIB_VER_SUBREVISION 0  /*@@ -696,7 +696,9 @@      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent    (such as zalloc being Z_NULL).  msg is left unchanged in both source and-   destination.+   destination.  If deflateCopy fails and dest is not Z_NULL, then dest->state+   is set to Z_NULL with dest otherwise unchanged, so that deflateEnd(dest) can+   be called safely, though dest is not a usable stream. */  ZEXTERN int ZEXPORT deflateReset(z_streamp strm);@@ -769,17 +771,17 @@ ZEXTERN z_size_t ZEXPORT deflateBound_z(z_streamp strm, z_size_t sourceLen); /*      deflateBound() returns an upper bound on the compressed size after-   deflation of sourceLen bytes.  It must be called after deflateInit() or-   deflateInit2(), and after deflateSetHeader(), if used.  This would be used-   to allocate an output buffer for deflation in a single pass, and so would be-   called before deflate().  If that first deflate() call is provided the-   sourceLen input bytes, an output buffer allocated to the size returned by-   deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed-   to return Z_STREAM_END.  Note that it is possible for the compressed size to-   be larger than the value returned by deflateBound() if flush options other-   than Z_FINISH or Z_NO_FLUSH are used.+  deflation of sourceLen bytes.  It must be called after deflateInit() or+  deflateInit2(), and after deflateSetHeader() or deflateSetDictionary(), if+  used.  This would be used to allocate an output buffer for deflation in a+  single pass, and so would be called before deflate().  If that first+  deflate() call is provided the sourceLen input bytes, an output buffer+  allocated to the size returned by deflateBound(), and the flush value+  Z_FINISH, then deflate() is guaranteed to return Z_STREAM_END.  Note that it+  is possible for the compressed size to be larger than the value returned by+  deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH are used. -     delfateBound_z() is the same, but takes and returns a size_t length.  Note+     deflateBound_z() is the same, but takes and returns a size_t length.  Note    that a long is 32 bits on Windows. */ @@ -789,7 +791,7 @@ /*      deflatePending() returns the number of bytes and bits of output that have    been generated, but not yet provided in the available output.  The bytes not-   provided would be due to the available output space having being consumed.+   provided would be due to the available output space having been consumed.    The number of bits of output not provided are between 0 and 7, where they    await more bits to join them in order to fill out a full byte.  If pending    or bits are Z_NULL, then those values are not set.@@ -869,8 +871,7 @@    instead.  windowBits must be greater than or equal to the windowBits value    provided to deflateInit2() while compressing, or it must be equal to 15 if    deflateInit2() was not used.  If a compressed stream with a larger window-   size is given as input, inflate() will return with the error code-   Z_DATA_ERROR instead of trying to allocate a larger window.+   size is given as input, inflate() may return with a Z_DATA_ERROR.       windowBits can also be zero to request that inflate use the window size in    the zlib header of the compressed stream.@@ -980,7 +981,9 @@      inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not    enough memory, Z_STREAM_ERROR if the source stream state was inconsistent    (such as zalloc being Z_NULL).  msg is left unchanged in both source and-   destination.+   destination.  If inflateCopy fails and dest is not Z_NULL, then dest->state+   is set to Z_NULL with dest otherwise unchanged, so that inflateEnd(dest) can+   be called safely, though dest is not a usable stream. */  ZEXTERN int ZEXPORT inflateReset(z_streamp strm);@@ -1095,9 +1098,10 @@    a terminating zero.  If any of extra, name, or comment are not present in    the header, then that field's pointer is set to Z_NULL.  This allows the use    of deflateSetHeader() with the returned structure to duplicate the header.-   Note that if those fields initially pointed to allocated memory, then the-   application will need to save them elsewhere so that they can be eventually-   freed.+   Though take care that none of the fields were truncated before so using it,+   lest havoc ensue.  Note that if those fields initially pointed to allocated+   memory, then the application will need to save them elsewhere so that they+   can be eventually freed.       If inflateGetHeader is not used, then the header information is simply    discarded.  The header is always checked for validity, including the header@@ -1394,8 +1398,8 @@    errno can be checked to determine if the reason gzopen failed was that the    file could not be opened. Note that if 'N' is in mode for non-blocking, the    open() itself can fail in order to not block. In that case gzopen() will-   return NULL and errno will be EAGAIN or ENONBLOCK. The call to gzopen() can-   then be re-tried. If the application would like to block on opening the+   return NULL and errno will be EAGAIN or EWOULDBLOCK. The call to gzopen()+   can then be re-tried. If the application would like to block on opening the    file, then it can use open() without O_NONBLOCK, and then gzdopen() with the    resulting file descriptor and 'N' in the mode, which will set it to non-    blocking.@@ -1501,9 +1505,12 @@      gzfread() returns the number of full items read of size size, or zero if    the end of the file was reached and a full item could not be read, or if    there was an error.  gzerror() must be consulted if zero is returned in-   order to determine if there was an error.  If the multiplication of size and-   nitems overflows, i.e. the product does not fit in a z_size_t, then nothing-   is read, zero is returned, and the error state is set to Z_STREAM_ERROR.+   order to determine if there was an error.  If some data was read before an+   error, then that data is returned until exhausted, after which the next call+   will return zero and gzerror() will report the error.  If the multiplication+   of size and nitems overflows, i.e. the product does not fit in a z_size_t,+   then nothing is read, zero is returned, and the error state is set to+   Z_STREAM_ERROR.       In the event that the end of file is reached and only a partial item is    available at the end, i.e. the remaining uncompressed data length is not a@@ -1569,7 +1576,7 @@    these possibilities can be determined using zlibCompileFlags().       If a Z_BUF_ERROR is returned, then nothing was written due to a stall on-   the non-blocking write destination.+   the non-blocking write destination. The operation can be retried. */  ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);@@ -1677,7 +1684,9 @@      gzseek returns the resulting offset location as measured in bytes from    the beginning of the uncompressed stream, or -1 in case of error, in    particular if the file is opened for writing and the new starting position-   would be before the current position.+   would be before the current position, or if the resulting position would+   not be representable in the offset type. If gzseek returns -1, the stream+   position is unchanged. */  ZEXTERN int ZEXPORT gzrewind(gzFile file);@@ -1778,7 +1787,8 @@    If errnum is not NULL, *errnum is set to zlib error number.  If an error    occurred in the file system and not in the compression library, *errnum is    set to Z_ERRNO and the application may consult errno to get the exact error-   code.+   code.  The error is reported by gzerror() as soon as it is detected, which+   may be before all of the data read prior to the error has been returned.       The application must not modify the returned string.  Future calls to    this function may invalidate the previously returned string.  If file is@@ -1972,7 +1982,8 @@  * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if  * both are true, the application gets the *64 functions, and the regular  * functions are changed to 64 bits) -- in case these are set on systems- * without large file support, _LFS64_LARGEFILE must also be true+ * without large file support, _LFS64_LARGEFILE must also be true, except on+ * native Windows, where 64-bit offsets are always available  */ #ifdef Z_LARGE64    ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);@@ -2029,7 +2040,7 @@  #endif /* !Z_SOLO */ -/* undocumented functions */+/* undocumented functions (not part of the zlib API) */ ZEXTERN const char   * ZEXPORT zError(int); ZEXTERN int            ZEXPORT inflateSyncPoint(z_streamp); ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
cbits/zutil.c view
@@ -171,7 +171,6 @@  void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) {     uchf *p = b;-    if (len == 0) return;     while (len) {         *p++ = 0;         len--;@@ -228,7 +227,11 @@     } else {         buf = farmalloc(bsize + 16L);     }-    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;+    if (buf == NULL) return NULL;+    if (next_ptr >= MAX_PTR) {+        farfree(buf);+        return NULL;+    }     table[next_ptr].org_ptr = buf;      /* Normalize the pointer to seg:0 */
changelog.md view
@@ -1,3 +1,7 @@+1.4 Bodigrim <andrew.lelechenko@gmail.com> November 2026++* update to zlib 1.4+ 1.3.2 Bodigrim <andrew.lelechenko@gmail.com> May 2026  * update to zlib 1.3.2
zlib-clib.cabal view
@@ -1,6 +1,6 @@ cabal-version:   2.4 name:            zlib-clib-version:         1.3.2+version:         1.4  copyright:       1995-2026 Jean-loup Gailly and Mark Adler license:         Zlib