diff --git a/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java b/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java index 4451aa7e5335..065c9aee7a27 100644 --- a/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java +++ b/src/java.base/share/classes/sun/security/provider/certpath/AlgorithmChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,6 +53,7 @@ import sun.security.util.ConstraintsParameters; import sun.security.util.Debug; import sun.security.util.DisabledAlgorithmConstraints; +import sun.security.util.KeyUtil; import sun.security.validator.Validator; import sun.security.x509.AlgorithmId; import sun.security.x509.X509CertImpl; @@ -224,7 +225,8 @@ public void check(Certificate cert, CertPathConstraintsParameters cp = new CertPathConstraintsParameters(trustedPubKey, variant, anchor, date); - dac.permits(trustedPubKey.getAlgorithm(), cp, true); + dac.permits(KeyUtil.getAlgorithm(trustedPubKey), + cp, true); } // Check the signature algorithm and parameters against constraints CertPathConstraintsParameters cp = diff --git a/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java b/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java index 796f922ae574..f179c9084abc 100644 --- a/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java +++ b/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,18 +35,15 @@ import java.security.cert.CertPathValidatorException; import java.security.cert.CertPathValidatorException.BasicReason; import java.security.interfaces.ECKey; -import java.security.interfaces.XECKey; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; import java.security.spec.MGF1ParameterSpec; -import java.security.spec.NamedParameterSpec; import java.security.spec.PSSParameterSpec; import java.time.DateTimeException; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -264,7 +261,7 @@ public final void permits(String algorithm, ConstraintsParameters cp, if (checkKey) { // Check if named curves in the key are disabled. for (Key key : cp.getKeys()) { - for (String curve : getNamedCurveFromKey(key)) { + for (String curve : getNamedParametersFromKey(key)) { if (!cachedCheckAlgorithm(curve)) { throw new CertPathValidatorException( "Algorithm constraints check failed on disabled " + @@ -278,16 +275,19 @@ public final void permits(String algorithm, ConstraintsParameters cp, algorithmConstraints.permits(algorithm, cp, checkKey); } - private static List getNamedCurveFromKey(Key key) { - if (key instanceof ECKey) { - NamedCurve nc = CurveDB.lookup(((ECKey)key).getParams()); - return (nc == null ? List.of() - : Arrays.asList(nc.getNameAndAliases())); - } else if (key instanceof XECKey) { - return List.of( - ((NamedParameterSpec)((XECKey)key).getParams()).getName()); + private static List getNamedParametersFromKey(Key key) { + if (key instanceof ECKey ecKey) { + NamedCurve nc = CurveDB.lookup(ecKey.getParams()); + if (nc == null) { + return List.of(); + } + return List.of(nc.getNameAndAliases()); } else { - return List.of(); + String n = KeyUtil.getAlgorithm(key); + if (n.equalsIgnoreCase(key.getAlgorithm())) { + return List.of(n); + } + return List.of(key.getAlgorithm(), n); } } @@ -312,12 +312,12 @@ private boolean checkConstraints(Set primitives, } // check the key algorithm - if (!permits(primitives, key.getAlgorithm(), null)) { + if (!permits(primitives, KeyUtil.getAlgorithm(key), null)) { return false; } // If this is an elliptic curve, check if it is disabled - for (String curve : getNamedCurveFromKey(key)) { + for (String curve : getNamedParametersFromKey(key)) { if (!permits(primitives, curve, null)) { return false; } @@ -471,7 +471,7 @@ private List getConstraints(String algorithm) { // Check if KeySizeConstraints permit the specified key public boolean permits(Key key) { - List list = getConstraints(key.getAlgorithm()); + List list = getConstraints(KeyUtil.getAlgorithm(key)); if (list == null) { return true; } @@ -525,7 +525,7 @@ public void permits(String algorithm, ConstraintsParameters cp, if (checkKey) { for (Key key : cp.getKeys()) { - algorithms.add(key.getAlgorithm()); + algorithms.add(KeyUtil.getAlgorithm(key)); } } diff --git a/src/java.base/share/classes/sun/security/util/KeyUtil.java b/src/java.base/share/classes/sun/security/util/KeyUtil.java index f9ac149ee4b7..e0a477a6e23b 100644 --- a/src/java.base/share/classes/sun/security/util/KeyUtil.java +++ b/src/java.base/share/classes/sun/security/util/KeyUtil.java @@ -201,6 +201,33 @@ public static final int getKeySize(AlgorithmParameters parameters) { return -1; } + /** + * If the key is a sub-algorithm of a larger group of algorithms, this + * method will return that sub-algorithm. For example, key.getAlgorithm() + * returns "EdDSA", but the underlying key may be "Ed448". For + * DisabledAlgorithmConstraints (DAC), this distinction is important. + * "EdDSA" means all curves for DAC, but when using it with + * KeyPairGenerator, "EdDSA" means "Ed25519". + */ + public static String getAlgorithm(Key key) { + /* + if (key instanceof PrivateKey ak && + ak.getParams() instanceof NamedParameterSpec nps) { + return nps.getName(); + } else if (key instanceof PublicKey ak && + ak.getParams() instanceof NamedParameterSpec nps) { + return nps.getName(); + } + */ + if (key instanceof PrivateKey || key instanceof PublicKey) { + AlgorithmParameterSpec params = KeyUtil.getParams(key); + if (params instanceof NamedParameterSpec nps) { + return nps.getName(); + } + } + return key.getAlgorithm(); + } + /** * Returns whether the key is valid or not. *

diff --git a/src/java.base/share/legal/zlib.md b/src/java.base/share/legal/zlib.md index c729c4248d48..d346a4d0c986 100644 --- a/src/java.base/share/legal/zlib.md +++ b/src/java.base/share/legal/zlib.md @@ -1,4 +1,4 @@ -## zlib v1.3.2 +## zlib v1.4 ### zlib License

diff --git a/src/java.base/share/native/libzip/zlib/ChangeLog b/src/java.base/share/native/libzip/zlib/ChangeLog
index 312753edadef..228a03afa1d7 100644
--- a/src/java.base/share/native/libzip/zlib/ChangeLog
+++ b/src/java.base/share/native/libzip/zlib/ChangeLog
@@ -1,6 +1,37 @@
 
                 ChangeLog file for zlib
 
+Changes in 1.4 (4 Nov 2026)
+- Change CMake library names on MSVC
+- Return z_off_t default to long for portability
+- Fail gzopen() with "x" if O_EXCL not available
+- Deliver all gzip data before reporting error
+- Fix gzwrite() buffer overflow (CVE-2026-85091)
+- Fix inflateGetDictionary() write past buffer on invalid window size
+- Fix window write overrun after inflateSync()
+- Fix read before provided data after repeated inflatePrime()'s
+- Fix write past pending buffer after repeated deflatePrime()'s
+- Fix copy of uninitialized memory by inflateBack() on invalid data
+- Fix copy of uninitialized memory after gzseek() as first write action
+- Fix read outside window after a deflateResetKeep() mid-stream
+- Avoid out-of-bounds pointer arithmetic in infback9() (CVE-2026-4738)
+- Fix several vulnerabilities in contrib/minizip
+- Fix truncated stream detection in gzread()
+- Fix pending skip handling in gzread()
+- Fix loss of zero fill on repeated gzseek()'s when writing
+- Fix inaccurate total_in after Z_NEED_DICT returned
+- Detect and report bad deflateSetDictionary() calls
+- Avoid undefined behaviors in C language usage
+- Fix minizip extra field overflows when almost full and need Zip64
+- Don't assume NULL is defined in compress.c and uncompr.c
+- Use the generated zconf.h when building test programs out of tree
+- Improve portability and functionality of CMake builds
+- Provide 64-bit file offsets on Windows with #defines as on Linux
+- Improve portability to Android, AIX, PowerPC, s390x, and Windows
+- Use a PCG random number generator instead of rand() in minizip
+- Clarify documentation
+- (See https://github.com/madler/zlib for all 195 commits)
+
 Changes in 1.3.2 (17 Feb 2026)
 - Continued rewrite of CMake build [Vollstrecker]
 - Various portability improvements
diff --git a/src/java.base/share/native/libzip/zlib/README b/src/java.base/share/native/libzip/zlib/README
index 2b1e6f36fe3e..265c8b47d316 100644
--- a/src/java.base/share/native/libzip/zlib/README
+++ b/src/java.base/share/native/libzip/zlib/README
@@ -1,6 +1,6 @@
 ZLIB DATA COMPRESSION LIBRARY
 
-zlib 1.3.2 is a general purpose data compression library.  All the code is
+zlib 1.4 is a general purpose data compression library.  All the code is
 thread safe (though see the FAQ for caveats).  The data format used by the zlib
 library is described by RFCs (Request for Comments) 1950 to 1952 at
 https://datatracker.ietf.org/doc/html/rfc1950 (zlib format), rfc1951 (deflate
@@ -31,7 +31,7 @@ Mark Nelson  wrote an article about zlib for the Jan.  1997
 issue of Dr.  Dobb's Journal; a copy of the article is available at
 https://zlib.net/nelson/ .
 
-The changes made in version 1.3.2 are documented in the file ChangeLog.
+The changes made in version 1.4 are documented in the file ChangeLog.
 
 Unsupported third party contributions are provided in directory contrib/ .
 
diff --git a/src/java.base/share/native/libzip/zlib/compress.c b/src/java.base/share/native/libzip/zlib/compress.c
index 54346ad2a2f1..832788e9248f 100644
--- a/src/java.base/share/native/libzip/zlib/compress.c
+++ b/src/java.base/share/native/libzip/zlib/compress.c
@@ -52,8 +52,8 @@ int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
     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;
diff --git a/src/java.base/share/native/libzip/zlib/deflate.c b/src/java.base/share/native/libzip/zlib/deflate.c
index 0ec56ec5691f..5918d8cb00b4 100644
--- a/src/java.base/share/native/libzip/zlib/deflate.c
+++ b/src/java.base/share/native/libzip/zlib/deflate.c
@@ -76,7 +76,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
@@ -469,7 +469,6 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
     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;
@@ -592,7 +591,8 @@ int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
         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 */
@@ -695,7 +695,20 @@ int ZEXPORT deflateResetKeep(z_streamp strm) {
         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;
 }
@@ -707,6 +720,7 @@ local void lm_init(deflate_state *s) {
     s->window_size = (ulg)2L*s->w_size;
 
     CLEAR_HASH(s);
+    s->matches = 0;             /* the hash is clear */
 
     /* Set the default configuration parameters:
      */
@@ -769,18 +783,23 @@ int ZEXPORT deflateUsed(z_streamp strm, int *bits) {
 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)
@@ -1340,39 +1359,49 @@ int ZEXPORT deflateEnd(z_streamp strm) {
  */
 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,
@@ -1665,7 +1694,10 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) {
 /* 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). */
@@ -1700,7 +1732,7 @@ local block_state deflate_stored(deflate_state *s, int flush) {
      * 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 {
@@ -1715,11 +1747,14 @@ local block_state deflate_stored(deflate_state *s, int flush) {
             /* 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
@@ -1727,13 +1762,13 @@ local block_state deflate_stored(deflate_state *s, int flush) {
          */
         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. */
@@ -2038,7 +2073,8 @@ local block_state deflate_slow(deflate_state *s, int flush) {
             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);
diff --git a/src/java.base/share/native/libzip/zlib/gzguts.h b/src/java.base/share/native/libzip/zlib/gzguts.h
index 0be646016ed8..70ca11af0bc3 100644
--- a/src/java.base/share/native/libzip/zlib/gzguts.h
+++ b/src/java.base/share/native/libzip/zlib/gzguts.h
@@ -116,8 +116,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
@@ -152,14 +154,28 @@
 #  include 
 #  define zstrerror() gz_strwinerror((DWORD)GetLastError())
 #else
+#  include 
 #  ifndef NO_STRERROR
-#    include 
 #    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 *);
@@ -238,3 +254,10 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
    (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)
diff --git a/src/java.base/share/native/libzip/zlib/gzlib.c b/src/java.base/share/native/libzip/zlib/gzlib.c
index 9489bcc1f12e..c62db8580075 100644
--- a/src/java.base/share/native/libzip/zlib/gzlib.c
+++ b/src/java.base/share/native/libzip/zlib/gzlib.c
@@ -92,9 +92,9 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
 /* Reset gzip file state */
 local void gz_reset(gz_statep state) {
     state->x.have = 0;              /* no output data available */
+    state->past = 0;                /* have not read past end yet */
     if (state->mode == GZ_READ) {   /* for reading ... */
         state->eof = 0;             /* not at end of file */
-        state->past = 0;            /* have not read past end yet */
         state->how = LOOK;          /* look for gzip header */
         state->junk = -1;           /* mark first member */
     }
@@ -112,9 +112,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
     gz_statep state;
     z_size_t len;
     int oflag = 0;
-#ifdef O_EXCL
     int exclusive = 0;
-#endif
 
     /* check input */
     if (path == NULL || mode == NULL)
@@ -160,11 +158,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
                 oflag |= O_CLOEXEC;
                 break;
 #endif
-#ifdef O_EXCL
             case 'x':
                 exclusive = 1;
                 break;
-#endif
             case 'f':
                 state->strategy = Z_FILTERED;
                 break;
@@ -220,10 +216,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
     /* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
        appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
 
+#ifndef O_EXCL
+    if (exclusive && state->mode != GZ_READ && fd < 0) {
+        /* exclusive creation request can't be honored -- fail out */
+        free(state);
+        return NULL;
+    }
+#endif
+
     /* save the path name for error messages */
 #ifdef WIDECHAR
-    if (fd == -2)
+    if (fd == -2) {
         len = wcstombs(NULL, path, 0);
+        if (len == (z_size_t)-1)
+            len = 0;            /* not representable in the current locale */
+    }
     else
 #endif
         len = strlen((const char *)path);
@@ -234,9 +241,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
     }
 #ifdef WIDECHAR
     if (fd == -2) {
-        if (len)
-            wcstombs(state->path, path, len + 1);
-        else
+        if (len == 0 || wcstombs(state->path, path, len + 1) != len)
             *(state->path) = 0;
     }
     else
@@ -245,7 +250,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
         (void)snprintf(state->path, len + 1, "%s", (const char *)path);
 #else
-        strcpy(state->path, path);
+        strcpy(state->path, (const char *)path);
 #endif
     }
 
@@ -279,9 +284,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
         if (oflag & O_NONBLOCK)
             fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
 #endif
-#ifdef O_CLOEXEC
+#if defined(O_CLOEXEC) && defined(FD_CLOEXEC)
         if (oflag & O_CLOEXEC)
-            fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_CLOEXEC);
+            fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
 #endif
         state->fd = fd;
     }
@@ -323,7 +328,7 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode) {
     char *path;         /* identifier for error messages */
     gzFile gz;
 
-    if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
+    if (fd < 0 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
         return NULL;
 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
     (void)snprintf(path, 7 + 3 * sizeof(int), "", fd);
@@ -390,7 +395,7 @@ int ZEXPORT gzrewind(gzFile file) {
 /* -- see zlib.h -- */
 z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
     unsigned n;
-    z_off64_t ret;
+    z_off64_t ret, pos;
     gz_statep state;
 
     /* get internal structure and check integrity */
@@ -408,18 +413,19 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
     if (whence != SEEK_SET && whence != SEEK_CUR)
         return -1;
 
-    /* normalize offset to a SEEK_CUR specification */
-    if (whence == SEEK_SET)
-        offset -= state->x.pos;
-    else {
-        offset += state->past ? 0 : state->skip;
-        state->skip = 0;
-    }
+    /* compute the absolute position */
+    pos = whence == SEEK_SET ? 0 :
+          state->x.pos + (state->past ? 0 : state->skip);
+    if (offset > GZ_OFF_MAX - pos)
+        return -1;                          /* would overflow z_off64_t */
+    if (offset < -pos)
+        return -1;                          /* before start of file */
+    pos += offset;
 
     /* if within raw area while reading, just go there */
-    if (state->mode == GZ_READ && state->how == COPY &&
-            state->x.pos + offset >= 0) {
-        ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
+    if (state->mode == GZ_READ && state->how == COPY) {
+        ret = LSEEK(state->fd, pos - state->x.pos - (z_off64_t)state->x.have,
+                    SEEK_CUR);
         if (ret == -1)
             return -1;
         state->x.have = 0;
@@ -428,20 +434,18 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
         state->skip = 0;
         gz_error(state, Z_OK, NULL);
         state->strm.avail_in = 0;
-        state->x.pos += offset;
-        return state->x.pos;
+        state->x.pos = pos;
+        return pos;
     }
 
-    /* calculate skip amount, rewinding if needed for back seek when reading */
-    if (offset < 0) {
+    /* rewind if needed for back seek when reading */
+    if (pos < state->x.pos) {
         if (state->mode != GZ_READ)         /* writing -- can't go backwards */
             return -1;
-        offset += state->x.pos;
-        if (offset < 0)                     /* before start of file! */
-            return -1;
-        if (gzrewind(file) == -1)           /* rewind, then skip to offset */
+        if (gzrewind(file) == -1)           /* rewind, then skip to pos */
             return -1;
     }
+    offset = pos - state->x.pos;
 
     /* if reading, skip what's in output buffer (one less gzgetc() check) */
     if (state->mode == GZ_READ) {
@@ -455,7 +459,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
 
     /* request skip (if not zero) */
     state->skip = offset;
-    return state->x.pos + offset;
+    return pos;
 }
 
 /* -- see zlib.h -- */
@@ -584,10 +588,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
         state->msg = NULL;
     }
 
-    /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
-    if (err != Z_OK && err != Z_BUF_ERROR && !state->again)
-        state->x.have = 0;
-
     /* set error code, and if no message, then done */
     state->err = err;
     if (msg == NULL)
diff --git a/src/java.base/share/native/libzip/zlib/gzread.c b/src/java.base/share/native/libzip/zlib/gzread.c
index 89144d2e56fe..ce7da3d0c999 100644
--- a/src/java.base/share/native/libzip/zlib/gzread.c
+++ b/src/java.base/share/native/libzip/zlib/gzread.c
@@ -57,7 +57,7 @@ local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
         *have += (unsigned)ret;
     } while (*have < len);
     if (ret < 0) {
-        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+        if (BLOCKED(errno)) {
             state->again = 1;
             if (*have != 0)
                 return 0;
@@ -149,6 +149,13 @@ local int gz_look(gz_statep state) {
        if we're looking for a gzip member after the first one, which is not at
        the start, then proceed directly to look for a gzip member next */
     if (state->direct == -1 || state->junk == 0) {
+        /* wait for input before committing to another gzip member */
+        if (state->junk == 0 && strm->avail_in == 0) {
+            if (gz_avail(state) == -1)
+                return -1;
+            if (strm->avail_in == 0)
+                return 0;
+        }
         inflateReset(strm);
         state->how = GZIP;
         state->junk = state->junk != -1;
@@ -177,7 +184,7 @@ local int gz_look(gz_statep state) {
             strm->next_in[2] == 8 && strm->next_in[3] < 32) {
         inflateReset(strm);
         state->how = GZIP;
-        state->junk = 1;
+        state->junk = 0;
         state->direct = 0;
         return 0;
     }
@@ -272,6 +279,11 @@ local int gz_decomp(gz_statep state) {
 local int gz_fetch(gz_statep state) {
     z_streamp strm = &(state->strm);
 
+    /* after a serious error, only what is already in the output buffer is
+       delivered -- don't try to decompress any more */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+        return -1;
+
     do {
         switch(state->how) {
         case LOOK:      /* -> LOOK, COPY (only if never GZIP), or GZIP */
@@ -300,32 +312,46 @@ local int gz_fetch(gz_statep state) {
     return 0;
 }
 
+/* Apply as much of a pending skip request as the output already available in
+   state->x allows. */
+local void gz_skip_have(gz_statep state) {
+    unsigned n;
+
+    n = GT_OFF(state->x.have) ||
+        (z_off64_t)state->x.have > state->skip ?
+        (unsigned)state->skip : state->x.have;
+    state->x.have -= n;
+    state->x.next += n;
+    state->x.pos += n;
+    state->skip -= n;
+}
+
 /* Skip state->skip (> 0) uncompressed bytes of output.  Return -1 on error, 0
    on success. */
 local int gz_skip(gz_statep state) {
-    unsigned n;
-
     /* skip over len bytes or reach end-of-file, whichever comes first */
     do {
         /* skip over whatever is in output buffer */
-        if (state->x.have) {
-            n = GT_OFF(state->x.have) ||
-                (z_off64_t)state->x.have > state->skip ?
-                (unsigned)state->skip : state->x.have;
-            state->x.have -= n;
-            state->x.next += n;
-            state->x.pos += n;
-            state->skip -= n;
-        }
+        if (state->x.have)
+            gz_skip_have(state);
 
         /* output buffer empty -- return if we're at the end of the input */
-        else if (state->eof && state->strm.avail_in == 0)
+        else if (state->eof && state->strm.avail_in == 0) {
+            if (state->how == GZIP && state->err == Z_OK)
+                gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+            state->skip = 0;
+            state->past = 1;
             break;
+        }
 
         /* need more data to skip -- load up output buffer */
         else {
-            /* get more output, looking for header if required */
-            if (gz_fetch(state) == -1)
+            /* get more output, looking for header if required. If the fetch
+               stalled but provided some output, consume it before returning
+               so that x.have > 0 always implies the data is at the current
+               logical position (x.pos), as assumed by the gzgetc() fast path
+               in zlib.h and gzread.c */
+            if (gz_fetch(state) == -1 && state->x.have == 0)
                 return -1;
         }
     } while (state->skip);
@@ -373,8 +399,11 @@ local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
         }
 
         /* output buffer empty -- return if we're at the end of the input */
-        else if (state->eof && state->strm.avail_in == 0)
+        else if (state->eof && state->strm.avail_in == 0) {
+            if (state->how == GZIP && state->err == Z_OK)
+                gz_error(state, Z_BUF_ERROR, "unexpected end of file");
             break;
+        }
 
         /* need output data -- for small len or new stream load up our output
            buffer, so that gzgetc() can be fast */
@@ -427,15 +456,21 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
     if (state->mode != GZ_READ)
         return -1;
 
-    /* check that there was no (serious) error */
-    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+    /* check that there was no (serious) error -- if there was, deliver any
+       data read before the error until it is exhausted, and only then return
+       the error */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+            state->x.have == 0)
         return -1;
-    gz_error(state, Z_OK, NULL);
+    if (state->again)
+        gz_error(state, Z_OK, NULL);
 
     /* since an int is returned, make sure len fits in one, otherwise return
-       with an error (this avoids a flaw in the interface) */
+       with an error (this avoids a flaw in the interface) -- keep a pending
+       serious error, which is the one the caller needs to see */
     if ((int)len < 0) {
-        gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
+        if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+            gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
         return -1;
     }
 
@@ -472,15 +507,22 @@ z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
     if (state->mode != GZ_READ)
         return 0;
 
-    /* check that there was no (serious) error */
-    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+    /* check that there was no (serious) error -- if there was, deliver any
+       data read before the error until it is exhausted, and only then return
+       the error */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+            state->x.have == 0)
         return 0;
-    gz_error(state, Z_OK, NULL);
+    if (state->again)
+        gz_error(state, Z_OK, NULL);
 
-    /* compute bytes to read -- error on overflow */
+    /* compute bytes to read -- error on overflow, keeping a pending serious
+       error, which is the one the caller needs to see */
     len = nitems * size;
     if (size && len / size != nitems) {
-        gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
+        if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+            gz_error(state, Z_STREAM_ERROR,
+                     "request does not fit in a size_t");
         return 0;
     }
 
@@ -505,10 +547,14 @@ int ZEXPORT gzgetc(gzFile file) {
     if (state->mode != GZ_READ)
         return -1;
 
-    /* check that there was no (serious) error */
-    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+    /* check that there was no (serious) error -- if there was, deliver any
+       data read before the error until it is exhausted, and only then return
+       the error, as the gzgetc() macro does */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+            state->x.have == 0)
         return -1;
-    gz_error(state, Z_OK, NULL);
+    if (state->again)
+        gz_error(state, Z_OK, NULL);
 
     /* try output buffer (no need to check for skip request) */
     if (state->x.have) {
@@ -540,10 +586,15 @@ int ZEXPORT gzungetc(int c, gzFile file) {
     if (state->how == LOOK && state->x.have == 0)
         (void)gz_look(state);
 
-    /* check that there was no (serious) error */
-    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+    /* check that there was no (serious) error -- a character can still be
+       pushed back after one, since it is data that was read before the
+       error, and it will be returned before the error is signaled -- but only
+       if there is an output buffer to put it in */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+            state->size == 0)
         return -1;
-    gz_error(state, Z_OK, NULL);
+    if (state->again)
+        gz_error(state, Z_OK, NULL);
 
     /* process a skip request */
     if (state->skip && gz_skip(state) == -1)
@@ -565,7 +616,8 @@ int ZEXPORT gzungetc(int c, gzFile file) {
 
     /* if no room, give up (must have already done a gzungetc()) */
     if (state->x.have == (state->size << 1)) {
-        gz_error(state, Z_DATA_ERROR, "out of room to push characters");
+        if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+            gz_error(state, Z_DATA_ERROR, "out of room to push characters");
         return -1;
     }
 
@@ -601,10 +653,14 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
     if (state->mode != GZ_READ)
         return NULL;
 
-    /* check that there was no (serious) error */
-    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+    /* check that there was no (serious) error -- if there was, deliver any
+       data read before the error until it is exhausted, and only then return
+       the error */
+    if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+            state->x.have == 0)
         return NULL;
-    gz_error(state, Z_OK, NULL);
+    if (state->again)
+        gz_error(state, Z_OK, NULL);
 
     /* process a skip request */
     if (state->skip && gz_skip(state) == -1)
@@ -616,8 +672,9 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
     left = (unsigned)len - 1;
     if (left) do {
         /* assure that something is in the output buffer */
-        if (state->x.have == 0 && gz_fetch(state) == -1)
-            break;                      /* error */
+        if (state->x.have == 0 && gz_fetch(state) == -1 &&
+                state->x.have == 0)
+            break;                      /* error, and nothing left to return */
         if (state->x.have == 0) {       /* end of file */
             state->past = 1;            /* read past end */
             break;                      /* return what we have */
@@ -641,7 +698,7 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
     /* append a terminating zero to the string (we don't check for a zero in
        the contents, let the user worry about that) -- return the terminated
        string, or if nothing was read, NULL */
-    if (buf == str)
+    if (buf == str && len > 1)
         return NULL;
     buf[0] = 0;
     return str;
@@ -658,8 +715,10 @@ int ZEXPORT gzdirect(gzFile file) {
 
     /* if the state is not known, but we can find out, then do so (this is
        mainly for right after a gzopen() or gzdopen()) */
-    if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+    if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) {
         (void)gz_look(state);
+        gz_skip_have(state);        /* apply skip to current buffer */
+    }
 
     /* return 1 if transparent, 0 if processing a gzip stream */
     return state->direct == 1;
diff --git a/src/java.base/share/native/libzip/zlib/gzwrite.c b/src/java.base/share/native/libzip/zlib/gzwrite.c
index b11c318d5432..cf933bef87b8 100644
--- a/src/java.base/share/native/libzip/zlib/gzwrite.c
+++ b/src/java.base/share/native/libzip/zlib/gzwrite.c
@@ -65,8 +65,8 @@ local int gz_init(gz_statep state) {
             gz_error(state, Z_MEM_ERROR, "out of memory");
             return -1;
         }
-        strm->next_in = NULL;
     }
+    strm->next_in = NULL;
 
     /* mark state as initialized */
     state->size = state->want;
@@ -103,7 +103,7 @@ local int gz_comp(gz_statep state, int flush) {
             put = strm->avail_in > max ? max : strm->avail_in;
             writ = (int)write(state->fd, strm->next_in, put);
             if (writ < 0) {
-                if (errno == EAGAIN || errno == EWOULDBLOCK)
+                if (BLOCKED(errno))
                     state->again = 1;
                 gz_error(state, Z_ERRNO, zstrerror());
                 return -1;
@@ -138,7 +138,7 @@ local int gz_comp(gz_statep state, int flush) {
                       (unsigned)(strm->next_out - state->x.next);
                 writ = (int)write(state->fd, state->x.next, put);
                 if (writ < 0) {
-                    if (errno == EAGAIN || errno == EWOULDBLOCK)
+                    if (BLOCKED(errno))
                         state->again = 1;
                     gz_error(state, Z_ERRNO, zstrerror());
                     return -1;
@@ -180,6 +180,11 @@ local int gz_zero(gz_statep state) {
     unsigned n;
     z_streamp strm = &(state->strm);
 
+    /* allocate memory if this is the first time through -- the input buffer
+       must exist before it is zeroed below */
+    if (state->size == 0 && gz_init(state) == -1)
+        return -1;
+
     /* consume whatever's left in the input buffer */
     if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
         return -1;
@@ -199,8 +204,14 @@ local int gz_zero(gz_statep state) {
         n -= strm->avail_in;
         state->x.pos += n;
         state->skip -= n;
-        if (ret == -1)
+        if (ret == -1) {
+            /* discard any unconsumed zero fill -- it was not yet accounted
+               for in state->skip, so it will be generated again when the
+               operation is retried */
+            strm->avail_in = 0;
+            strm->next_in = state->in;
             return -1;
+        }
     } while (state->skip);
     return 0;
 }
@@ -266,9 +277,13 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
             n -= state->strm.avail_in;
             state->x.pos += n;
             len -= n;
-            if (ret == -1)
+            if (ret == -1) {
+                state->strm.avail_in = 0;
+                state->strm.next_in = state->in;
                 return state->again ? put - len : 0;
+            }
         } while (len);
+        state->strm.next_in = state->in;
     }
 
     /* input was all buffered or compressed */
@@ -395,9 +410,10 @@ int ZEXPORT gzputs(gzFile file, const char *s) {
     return len && put == 0 ? -1 : (int)put;
 }
 
-#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || !defined(NO_vsnprintf)) && \
-     (defined(STDC) || defined(Z_HAVE_STDARG_H) || !defined(NO_snprintf))) || \
-    defined(ZLIB_INSECURE)
+#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || \
+      !defined(NO_vsnprintf)) && \
+     (defined(STDC) || defined(Z_HAVE_STDARG_H) || \
+     !defined(NO_snprintf))) || defined(ZLIB_INSECURE)
 /* If the second half of the input buffer is occupied, write out the contents.
    If there is any input remaining due to a non-blocking stall on write, move
    it to the start of the buffer. Return true if this did not open up the
@@ -407,7 +423,8 @@ local int gz_vacate(gz_statep state) {
     z_streamp strm;
 
     strm = &(state->strm);
-    if (strm->next_in + strm->avail_in <= state->in + state->size)
+    if (strm->next_in == NULL ||
+        strm->next_in + strm->avail_in <= state->in + state->size)
         return 0;
     (void)gz_comp(state, Z_NO_FLUSH);
     if (strm->avail_in == 0) {
@@ -467,6 +484,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
                a Z_BUF_ERROR to let the application know that this gzprintf()
                needs to be retried. */
             gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+            return state->err;
         }
         if (!state->again)
             return state->err;
@@ -502,6 +520,14 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
 
     /* write out buffer if more than half is occupied */
     ret = gz_vacate(state);
+    if (ret) {
+        /* discard unwritten formatted output */
+        strm->avail_in -= (unsigned)len;
+        state->x.pos -= len;
+        if (state->again)
+            gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+        return state->err;
+    }
     if (state->err && !state->again)
         return state->err;
     return len;
@@ -575,6 +601,7 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
                a Z_BUF_ERROR to let the application know that this gzprintf()
                needs to be retried. */
             gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+            return state->err;
         }
         if (!state->again)
             return state->err;
@@ -615,6 +642,14 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
 
     /* write out buffer if more than half is occupied */
     ret = gz_vacate(state);
+    if (ret) {
+        /* discard unwritten formatted output */
+        strm->avail_in -= (unsigned)len;
+        state->x.pos -= len;
+        if (state->again)
+            gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+        return state->err;
+    }
     if (state->err && !state->again)
         return state->err;
     return (int)len;
diff --git a/src/java.base/share/native/libzip/zlib/infback.c b/src/java.base/share/native/libzip/zlib/infback.c
index 0becbb9eb4f6..c2286bd20699 100644
--- a/src/java.base/share/native/libzip/zlib/infback.c
+++ b/src/java.base/share/native/libzip/zlib/infback.c
@@ -447,8 +447,6 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
             /* 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;
diff --git a/src/java.base/share/native/libzip/zlib/inflate.c b/src/java.base/share/native/libzip/zlib/inflate.c
index c548f98f6de3..16bc832948e3 100644
--- a/src/java.base/share/native/libzip/zlib/inflate.c
+++ b/src/java.base/share/native/libzip/zlib/inflate.c
@@ -151,6 +151,14 @@ int ZEXPORT inflateReset(z_streamp strm) {
 
     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;
@@ -189,8 +197,8 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
     }
 
     /* 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);
 }
 
@@ -561,13 +569,13 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
             }
             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"));
@@ -724,6 +732,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
         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);
@@ -936,7 +945,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
             state->mode = LEN;
                 /* fallthrough */
         case LEN:
-            if (have >= 6 && left >= 258) {
+            if (have >= 6 && left >= 258 && bits < 8) {
                 RESTORE();
                 inflate_fast(strm, out);
                 LOAD();
@@ -1215,7 +1224,8 @@ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
     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;
@@ -1320,15 +1330,23 @@ int ZEXPORT inflateSync(z_streamp strm) {
 
     /* 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;
 }
@@ -1355,14 +1373,21 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
     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) {
@@ -1370,6 +1395,7 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
                  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
         if (window == Z_NULL) {
             ZFREE(source, copy);
+            dest->state = Z_NULL;
             return Z_MEM_ERROR;
         }
     }
@@ -1415,6 +1441,10 @@ int ZEXPORT inflateValidate(z_streamp strm, int check) {
         state->wrap |= 4;
     else
         state->wrap &= ~4;
+    if (check && state->reqwrap)
+        state->reqwrap |= 4;
+    else
+        state->reqwrap &= ~4;
     return Z_OK;
 }
 
diff --git a/src/java.base/share/native/libzip/zlib/inflate.h b/src/java.base/share/native/libzip/zlib/inflate.h
index 7828fb5db38e..1f2783e58cf8 100644
--- a/src/java.base/share/native/libzip/zlib/inflate.h
+++ b/src/java.base/share/native/libzip/zlib/inflate.h
@@ -109,6 +109,7 @@ struct inflate_state {
     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 */
@@ -117,7 +118,8 @@ struct inflate_state {
     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 */
diff --git a/src/java.base/share/native/libzip/zlib/inftrees.c b/src/java.base/share/native/libzip/zlib/inftrees.c
index 5f5d6b4baef2..7486efef8ee9 100644
--- a/src/java.base/share/native/libzip/zlib/inftrees.c
+++ b/src/java.base/share/native/libzip/zlib/inftrees.c
@@ -47,7 +47,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
@@ -95,7 +95,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
         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,
diff --git a/src/java.base/share/native/libzip/zlib/inftrees.h b/src/java.base/share/native/libzip/zlib/inftrees.h
index b9b4fc2fb2bc..51f67b68c65b 100644
--- a/src/java.base/share/native/libzip/zlib/inftrees.h
+++ b/src/java.base/share/native/libzip/zlib/inftrees.h
@@ -70,8 +70,14 @@ typedef struct {
    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() */
diff --git a/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java b/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
index dfde58f0122d..46affe2cd5e2 100644
--- a/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
+++ b/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
@@ -1,6 +1,6 @@
-Changes in JDK's in-tree zlib compared to upstream zlib 1.3.2
+Changes in JDK's in-tree zlib compared to upstream zlib 1.4
 
-(1) renamed adler32.c -> zadler32.c, crc32c -> zcrc32.c
+(1) renamed adler32.c -> zadler32.c, crc32.c -> zcrc32.c
 
 
   
diff --git a/src/java.base/share/native/libzip/zlib/trees.c b/src/java.base/share/native/libzip/zlib/trees.c
index cc7b136bcf68..bf5c1b24149e 100644
--- a/src/java.base/share/native/libzip/zlib/trees.c
+++ b/src/java.base/share/native/libzip/zlib/trees.c
@@ -251,7 +251,7 @@ local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
         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));
     }
 }
 
diff --git a/src/java.base/share/native/libzip/zlib/uncompr.c b/src/java.base/share/native/libzip/zlib/uncompr.c
index 25da59461c37..d55a4f2d66ca 100644
--- a/src/java.base/share/native/libzip/zlib/uncompr.c
+++ b/src/java.base/share/native/libzip/zlib/uncompr.c
@@ -57,8 +57,8 @@ int ZEXPORT uncompress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
     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;
diff --git a/src/java.base/share/native/libzip/zlib/zconf.h b/src/java.base/share/native/libzip/zlib/zconf.h
index d4589739a0ae..542e462ac177 100644
--- a/src/java.base/share/native/libzip/zlib/zconf.h
+++ b/src/java.base/share/native/libzip/zlib/zconf.h
@@ -523,6 +523,10 @@ typedef uLong FAR uLongf;
 
 #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)
@@ -540,7 +544,7 @@ typedef uLong FAR uLongf;
 #endif
 
 #ifndef z_off_t
-#  define z_off_t long long
+#  define z_off_t long
 #endif
 
 #if !defined(_WIN32) && defined(Z_LARGE64)
@@ -555,6 +559,11 @@ typedef uLong FAR uLongf;
 #  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 */
 #if defined(__MVS__)
   #pragma map(deflateInit_,"DEIN")
diff --git a/src/java.base/share/native/libzip/zlib/zcrc32.c b/src/java.base/share/native/libzip/zlib/zcrc32.c
index 133cbe158aa4..0161f1ee20e8 100644
--- a/src/java.base/share/native/libzip/zlib/zcrc32.c
+++ b/src/java.base/share/native/libzip/zlib/zcrc32.c
@@ -710,7 +710,7 @@ uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len) {
 #endif
 
             /* Initialize the CRC for each braid. */
-            crc0 = crc;
+            crc0 = (z_crc_t)crc;
 #if N > 1
             crc1 = 0;
 #if N > 2
diff --git a/src/java.base/share/native/libzip/zlib/zlib.h b/src/java.base/share/native/libzip/zlib/zlib.h
index 90230f4f23fb..15b6b927a10c 100644
--- a/src/java.base/share/native/libzip/zlib/zlib.h
+++ b/src/java.base/share/native/libzip/zlib/zlib.h
@@ -23,7 +23,7 @@
  */
 
 /* 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
 
@@ -65,11 +65,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
 
 /*
@@ -720,7 +720,9 @@ ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
      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);
@@ -793,17 +795,17 @@ ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen);
 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.
-
-     delfateBound_z() is the same, but takes and returns a size_t length.  Note
+  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.
+
+     deflateBound_z() is the same, but takes and returns a size_t length.  Note
    that a long is 32 bits on Windows.
 */
 
@@ -813,7 +815,7 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
 /*
      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.
@@ -893,8 +895,7 @@ ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
    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.
@@ -1004,7 +1005,9 @@ ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
      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);
@@ -1119,9 +1122,10 @@ ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
    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
@@ -1418,8 +1422,8 @@ ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
    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.
@@ -1525,9 +1529,12 @@ ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
      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
@@ -1593,7 +1600,7 @@ ZEXTERN int ZEXPORTVA gzprintf();
    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);
@@ -1701,7 +1708,9 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
      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);
@@ -1802,7 +1811,8 @@ ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
    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
@@ -1996,7 +2006,8 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file);       /* backward compatibility */
  * 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 *);
@@ -2053,7 +2064,7 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file);       /* backward compatibility */
 
 #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);
diff --git a/src/java.base/share/native/libzip/zlib/zutil.c b/src/java.base/share/native/libzip/zlib/zutil.c
index c57c162ffde8..ae5e85102786 100644
--- a/src/java.base/share/native/libzip/zlib/zutil.c
+++ b/src/java.base/share/native/libzip/zlib/zutil.c
@@ -195,7 +195,6 @@ int ZLIB_INTERNAL zmemcmp(const void FAR *s1, const void FAR *s2, z_size_t n) {
 
 void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) {
     uchf *p = b;
-    if (len == 0) return;
     while (len) {
         *p++ = 0;
         len--;
@@ -252,7 +251,11 @@ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
     } 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 */
diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java b/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java
index 2b62d18cb6f1..f3ef562fe425 100644
--- a/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java
+++ b/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -189,7 +189,7 @@ public int read(String name, ByteBuffer dst) throws IOException {
                 int n = read(name, address, rem);
 
                 // copy from buffer into backing array
-                int off = dst.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET;
+                long off = dst.arrayOffset() + pos + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET;
                 unsafe.copyMemory(null, address, dst.array(), off, n);
                 dst.position(pos + n);
 
@@ -251,7 +251,7 @@ public int write(String name, ByteBuffer src) throws IOException {
 
                 if (src.hasArray()) {
                     // copy from backing array into buffer
-                    int off = src.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET;
+                    long off = src.arrayOffset() + pos + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET;
                     unsafe.copyMemory(src.array(), off, null, address, rem);
                 } else {
                     // backing array not accessible so transfer via temporary array
diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
index c6c59fae89a8..03113a7f50f5 100644
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -912,56 +912,56 @@ protected void writePrimitiveArray(TypeArray array) throws IOException {
 
     private void writeBooleanArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE;
+             long offset = (long) BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE;
              out.writeBoolean(array.getHandle().getJBooleanAt(offset));
         }
     }
 
     private void writeByteArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = BYTE_BASE_OFFSET + index * BYTE_SIZE;
+             long offset = (long) BYTE_BASE_OFFSET + index * BYTE_SIZE;
              out.writeByte(array.getHandle().getJByteAt(offset));
         }
     }
 
     private void writeShortArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = SHORT_BASE_OFFSET + index * SHORT_SIZE;
+             long offset = (long) SHORT_BASE_OFFSET + index * SHORT_SIZE;
              out.writeShort(array.getHandle().getJShortAt(offset));
         }
     }
 
     private void writeIntArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = INT_BASE_OFFSET + index * INT_SIZE;
+             long offset = (long) INT_BASE_OFFSET + index * INT_SIZE;
              out.writeInt(array.getHandle().getJIntAt(offset));
         }
     }
 
     private void writeLongArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = LONG_BASE_OFFSET + index * LONG_SIZE;
+             long offset = (long) LONG_BASE_OFFSET + index * LONG_SIZE;
              out.writeLong(array.getHandle().getJLongAt(offset));
         }
     }
 
     private void writeCharArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = CHAR_BASE_OFFSET + index * CHAR_SIZE;
+             long offset = (long) CHAR_BASE_OFFSET + index * CHAR_SIZE;
              out.writeChar(array.getHandle().getJCharAt(offset));
         }
     }
 
     private void writeFloatArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = FLOAT_BASE_OFFSET + index * FLOAT_SIZE;
+             long offset = (long) FLOAT_BASE_OFFSET + index * FLOAT_SIZE;
              out.writeFloat(array.getHandle().getJFloatAt(offset));
         }
     }
 
     private void writeDoubleArray(TypeArray array, int length) throws IOException {
         for (int index = 0; index < length; index++) {
-             long offset = DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE;
+             long offset = (long) DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE;
              out.writeDouble(array.getHandle().getJDoubleAt(offset));
         }
     }
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
index 0e8f5bd55644..731be0591097 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java
@@ -3680,7 +3680,7 @@ static long booleanArrayAddress(boolean[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
index ac19b64f8095..dc8e03ba88ee 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java
@@ -3287,7 +3287,7 @@ static long arrayAddress(double[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
index 4fdfbb80a205..7ca86ed6b174 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java
@@ -3274,7 +3274,7 @@ static long arrayAddress(float[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
index 7bd0da683cb5..70c30c7103f4 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java
@@ -3383,7 +3383,7 @@ static long arrayAddress(int[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
index da6657bc217c..0142a930e02d 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java
@@ -3286,7 +3286,7 @@ static long arrayAddress(long[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
index 6284208535ee..ec2e524fdfd1 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
@@ -3672,7 +3672,7 @@ static long charArrayAddress(char[] a, int index) {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template
index 355645a2f6e0..0d53dfddcbbc 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template
@@ -4655,7 +4655,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
 
     @ForceInline
     static long byteArrayAddress(byte[] a, int index) {
-        return Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
+        return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index;
     }
 
     // ================================================
diff --git a/test/jdk/sun/security/util/AlgorithmConstraints/DisabledAlgorithmPermits.java b/test/jdk/sun/security/util/AlgorithmConstraints/DisabledAlgorithmPermits.java
new file mode 100644
index 000000000000..913aa1266f46
--- /dev/null
+++ b/test/jdk/sun/security/util/AlgorithmConstraints/DisabledAlgorithmPermits.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import sun.security.util.DisabledAlgorithmConstraints;
+
+import java.security.CryptoPrimitive;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+import java.security.Security;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+/*
+ * @test
+ * @bug 8346129
+ * @modules java.base/sun.security.util
+ * @summary Check DisabledAlgorithmConstraints using EdDSA & XDH against
+ * permit(Set, String, AP) and
+ * permit(Set, Key).  Results will differ based
+ * on method used.  The first method only can compare the String with the
+ * algorithms.  The second can check the algorithm and NamedParameterSpec
+ * while results in more 'false' cases.
+ *
+ * @run main/othervm DisabledAlgorithmPermits Ed25519
+ * @run main/othervm DisabledAlgorithmPermits Ed448
+ * @run main/othervm DisabledAlgorithmPermits EdDSA
+ * @run main/othervm DisabledAlgorithmPermits X25519
+ * @run main/othervm DisabledAlgorithmPermits X448
+ * @run main/othervm DisabledAlgorithmPermits XDH
+ */
+
+public class DisabledAlgorithmPermits {
+    public static void main(String[] args) throws Exception {
+        String algorithm = args[0];
+        Security.setProperty("x", algorithm);
+
+        // Expected table are the expected results from the test
+        List expected = switch (algorithm) {
+            case "Ed25519" ->
+                Arrays.asList(
+                    new TestCase("EdDSA", true),
+                    new TestCase("Ed25519", false),
+                    new TestCase("Ed448", true),
+                    new TestCase("X448", true),
+                    new TestCase(1,"EdDSA", false),
+                    new TestCase(1,"Ed25519", false),
+                    new TestCase(1,"Ed448", true),
+                    new TestCase(1,"X448", true));
+            case "Ed448" ->
+                Arrays.asList(
+                    new TestCase("EdDSA", true),
+                    new TestCase("Ed25519", true),
+                    new TestCase("Ed448", false),
+                    new TestCase("X448", true),
+                    new TestCase(1,"EdDSA", true),
+                    new TestCase(1,"Ed25519", true),
+                    new TestCase(1,"Ed448", false),
+                    new TestCase(1,"X448", true));
+            case "EdDSA" ->
+                Arrays.asList(
+                    new TestCase("EdDSA", false),
+                    new TestCase("Ed25519", true),
+                    new TestCase("Ed448", true),
+                    new TestCase("X448", true),
+                    new TestCase(1,"EdDSA", false),
+                    new TestCase(1,"Ed25519", false),
+                    new TestCase(1,"Ed448", false),
+                    new TestCase(1,"X448", true));
+            case "X25519" ->
+                Arrays.asList(
+                    new TestCase("XDH", true),
+                    new TestCase("X25519", false),
+                    new TestCase("X448", true),
+                    new TestCase("Ed448", true),
+                    new TestCase(1, "XDH", false),
+                    new TestCase(1, "X25519", false),
+                    new TestCase(1, "X448", true),
+                    new TestCase(1, "Ed448", true));
+            case "X448" ->
+                Arrays.asList(
+                    new TestCase("XDH", true),
+                    new TestCase("X25519", true),
+                    new TestCase("X448", false),
+                    new TestCase("Ed448", true),
+                    new TestCase(1, "XDH", true),
+                    new TestCase(1, "X25519", true),
+                    new TestCase(1, "X448", false),
+                    new TestCase(1, "Ed448", true));
+            case "XDH" ->
+                Arrays.asList(
+                    new TestCase("XDH", false),
+                    new TestCase("X25519", true),
+                    new TestCase("X448", true),
+                    new TestCase("Ed448", true),
+                    new TestCase(1, "XDH", false),
+                    new TestCase(1, "X25519", false),
+                    new TestCase(1, "X448", false),
+                    new TestCase(1, "Ed448", true));
+            default -> null;
+        };
+
+        Objects.requireNonNull(expected, "algorithm being tested " +
+            algorithm + " not in expected table");
+        System.out.println("---");
+        var dac = new DisabledAlgorithmConstraints("x");
+        System.out.println("disabled algorithms = " + Security.getProperty("x"));
+
+        // Using only testType 0, this tests that permit(Set<>, String, null)
+        // will check only the algorithm against the disabled list
+        expected.stream().filter(n->n.testType == 0).forEach(tc -> {
+            boolean r = dac.permits(Set.of(CryptoPrimitive.SIGNATURE),
+                    tc.testAlgo, null);
+            System.out.print("\tpermits(Set.of(CryptoPrimitive.SIGNATURE), \"" +
+                tc.testAlgo + "\", null): " + r + " : " );
+            if (r != tc.expected) {
+                System.out.println("failed.");
+                throw new AssertionError("failed.  Expected " +
+                    tc.expected);
+            }
+            System.out.println("pass");
+        });
+
+        // Using only testType 1, this tests permit(Set<>, Key) that will look
+        // at both the key.getAlgorithm() and the key.getParams().getName()
+        // against the disabled list
+        expected.stream().filter(n->n.testType == 1).forEach(tc -> {
+            PrivateKey k;
+            try {
+                k = KeyPairGenerator.getInstance(tc.testAlgo).generateKeyPair().
+                    getPrivate();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            boolean r = dac.permits(Set.of(CryptoPrimitive.SIGNATURE), k);
+            System.out.print("\tpermits(Set.of(CryptoPrimitive.SIGNATURE), " +
+                tc.testAlgo + " privkey): " + r + " : " );
+            if (r != tc.expected) {
+                System.out.println("failed.");
+                throw new AssertionError("failed.  Expected " +
+                    tc.expected);
+            }
+            System.out.println("pass");
+        });
+        System.out.println("---");
+    }
+
+    record TestCase(int testType, String testAlgo, boolean expected) {
+        TestCase(String testAlgo, boolean expected) {
+            this(0, testAlgo, expected);
+        }
+    }
+}
+