critical

CVE

CVE-2026-85091, CVE-2026-4738

CWE

CWE-787, CWE-125, CWE-415, CWE-22, CWE-843, CWE-908

Affected Surface

  • C / C++ library `zlib` (`madler/zlib`) versions `<= 1.3.2` (fixed in `1.4`, released 4-5 November 2026), including `1.3.1` through `1.3.2` for `CVE-2026-85091` (`TOB-ZLIB-003`) and `THM-ZLIB-001`
  • Bundled `contrib/minizip` and `miniunz` in `zlib <= 1.3.2` (`block_central_name()` double free, `zipAlreadyThere()` NULL dereference, Zip64 extra-field out-of-bounds read, and `miniunz` directory/Windows path traversal)
  • CPython (`python/cpython`) versions `<= 3.14.x` (`Objects/genericaliasobject.c` `_Py_subs_parameters()`, fixed on `main` / `3.15` in commit `3c9c477f508a` / PR `#155761`, not backported by upstream to `3.12`, `3.13`, or `3.14`)
  • AI/ML inference servers and Python template sandboxes (including vLLM and Hugging Face `chat_template.jinja` evaluators using Jinja2 `SandboxedEnvironment` or `ImmutableSandboxedEnvironment`) that render untrusted model templates on CPython

TL;DR

On 4 and 5 November 2026, two foundational C runtime disclosures landed on oss-security:

  1. zlib 1.4 (CVE-2026-85091, THM-ZLIB-001, and Trail of Bits TOB-ZLIB-003 through TOB-ZLIB-014): Mark Adler released zlib 1.4 (oss-security 2026/11/05/10), fixing 13 security flaws across core libz and contrib/minizip:
    • CVE-2026-85091 (TOB-ZLIB-003, CVSS 7.4 High): When gz_write() wrote to a non-blocking file descriptor that stalled (EAGAIN / EWOULDBLOCK) on the direct caller-buffer path, it returned early without resetting state->strm.avail_in and state->strm.next_in, leaving next_in pointing into the caller’s external buffer. A subsequent gzprintf() or gzvprintf() call invoked gz_vacate(), which computed memmove() using the stale external pointer and overflowed state->in.
    • Theorem THM-ZLIB-001 (8 MB out-of-bounds heap write in inflateGetDictionary()): In zlib 1.3.1 and 1.3.2, inflate() overwrote state->wbits with the zlib header’s window size len (BITS(4) + 8, up to 23) before checking len > 15. If the caller then called inflateReset() or inflateSync(), state->wbits stayed up to 23 (1U << 23 = 8 MiB), and a later inflateGetDictionary() copied up to 8 MiB into the caller’s 32 KiB buffer.
    • Trail of Bits TOB-ZLIB-004, TOB-ZLIB-008, TOB-ZLIB-009, TOB-ZLIB-013, TOB-ZLIB-014, plus uninitialized memory disclosures and minizip flaws: inflateSync() before a header was seen allocated a 1-byte window that a reused stream could overrun (TOB-ZLIB-004); repeated deflatePrime() calls overflowed pending_buf (TOB-ZLIB-013); inflatePrime() left next_in pointing before the start of the input buffer (TOB-ZLIB-014); inflateBack(), deflateResetKeep(), and forward gzseek() leaked uninitialized heap or out-of-window memory; and contrib/minizip fixed a double free in block_central_name(), a NULL dereference in zipAlreadyThere(), Zip64 extra-field over-reads, and directory/Windows path traversal in miniunz.
  2. CPython types.GenericAlias _Py_subs_parameters() out-of-bounds read and Jinja2 / vLLM sandbox escape (gh-155752 / python/cpython#155761): Disclosed by Darius Houle of RunSybil on 3 November 2026 and posted to oss-security 2026/11/05/11, CPython’s _Py_subs_parameters() in Objects/genericaliasobject.c caches a generic alias’s parameters tuple (__parameters__) before invoking __typing_prepare_subst__ hooks during type subscription (alias[...]). If a preparation callback attaches __typing_subst__ to an argument that did not have it when __parameters__ was cached, tuple_index(parameters, nparams, arg) returns -1. Because assert(iparam >= 0) is compiled out in release builds, CPython executes PyObject_CallOneArg(subst, argitems[-1]), passing the 8-byte word immediately before the tuple’s element array as a live PyObject * argument to the callback. On CPython >= 3.14, that word is the tuple’s cached hash (ob_hash), letting a crafted Jinja2 template choose two integers whose tuple hash equals a leaked address (from ''.maketrans), forge references to str, type, code, and function, and escape ImmutableSandboxedEnvironment inside a Hugging Face chat_template.jinja loaded by vLLM or BYOM inference services. Because neither CPython nor Jinja2 considers Python-level sandboxing a supported security boundary, upstream merged python/cpython#155761 on main (3.15) without backporting it to 3.12, 3.13, or 3.14.

What to do now: Upgrade native and bundled copies of zlib and minizip to 1.4. If you operate vLLM, TGI, or custom LLM serving pipelines that render model-supplied chat_template.jinja files, do not rely on Jinja2’s SandboxedEnvironment or ImmutableSandboxedEnvironment as a host isolation boundary: apply patch python/cpython#155761 to your Python runtime or isolate untrusted model rendering inside an unprivileged container/microVM without host credentials.

Affected packages and components

EcosystemPackage / ComponentCVE / IdentifierSeverityAffected versionsFixed / Safe versionVulnerable location
C / C++zlib (libz)CVE-2026-85091 (TOB-ZLIB-003)CVSS 7.4 High1.3.1.2 through 1.3.21.4 (commit df84af25dc19)gz_write() and gz_vacate() in gzwrite.c
C / C++zlib (libz)THM-ZLIB-001, TOB-ZLIB-004, TOB-ZLIB-014High1.3.1 through 1.3.2 (THM-ZLIB-001); <= 1.3.2 (TOB-ZLIB-004, 014)1.4 (commits 2fd31f00740e, 8179479c6274, e7bb9788e0f0)inflate(), inflateSync(), inflateGetDictionary(), and inflatePrime() in inflate.c
C / C++zlib (libz)TOB-ZLIB-013, TOB-ZLIB-008, TOB-ZLIB-009, e9415f70eb6a, 1e4178b27f45Medium / High<= 1.3.21.4 (commits 12d7b9098091, 2ec717a141cb, e9415f70eb6a, 1e4178b27f45)deflatePrime() and deflateResetKeep() in deflate.c, gzdopen() in gzlib.c, gz_zero() in gzwrite.c
C / C++zlib (contrib/minizip)2804ba757385, 6201bd6046fc, 4c94e39fc370, fd54d99ea361High<= 1.3.21.4block_central_name() and zipAlreadyThere() in contrib/minizip/zip.c, unzip.c, and miniunz.c
Python / Ccpython (python3)gh-155752 (PR #155761)High / Critical (in sandboxed AI/template hosts)<= 3.14.x (exploited via tuple ob_hash on 3.14.x)Patched on main (3c9c477f508a); not backported to 3.12-3.14_Py_subs_parameters() in Objects/genericaliasobject.c

Technical analysis

1. zlib 1.4: CVE-2026-85091 (gz_write stale pointer) and THM-ZLIB-001 (inflateGetDictionary 8 MB OOB write)

In gzwrite.c, when gz_write() is given a buffer at least as large as state->size, it compresses directly from the caller’s buf (state->strm.next_in = (z_const Bytef *)buf) instead of copying through state->in. If the underlying file descriptor is non-blocking and gz_comp() stalls with EAGAIN / EWOULDBLOCK (ret == -1), gz_write() in zlib 1.3.1.2 through 1.3.2 returned early while leaving state->strm.avail_in non-zero and state->strm.next_in pointing into the caller’s external buffer. If the caller next invoked gzprintf() or gzvprintf(), gz_vacate() assumed state->strm.next_in pointed inside state->in and called memmove(state->in, state->strm.next_in, state->strm.avail_in), overflowing state->in. Commit df84af25dc19 clears both fields before returning on a non-blocking stall, and commit 2fd31f00740e fixes the THM-ZLIB-001 window-size ordering bug in inflate.c:

--- a/gzwrite.c
+++ b/gzwrite.c
@@ -242,8 +242,11 @@ 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);
     }
--- a/inflate.c
+++ b/inflate.c
@@ -545,13 +545,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;

In inflate.c, when a stream was initialized with windowBits = 0 (telling inflate() to read the window size from the zlib header), a crafted 2-byte header with a 4-bit window field > 7 set len = BITS(4) + 8 (up to 23) and assigned state->wbits = len before rejecting len > 15. Calling inflateReset() or inflateSync() preserved state->wbits = 23, allowing updatewindow() to allocate an 8 MiB sliding window and inflateGetDictionary() to write up to 8 MiB past a caller’s standard 32 KiB dictionary buffer.

2. CPython types.GenericAlias (gh-155752 / PR #155761): turning argitems[-1] into a PyObject *

When Python evaluates a generic alias subscription such as dict[first, second, late][arg_tuple], _Py_subs_parameters() in Objects/genericaliasobject.c first caches the parameter tuple (parameters = self->parameters) and runs each parameter’s __typing_prepare_subst__ hook. It then loops over the alias’s args and checks whether each arg has a __typing_subst__ attribute.

If a preparation hook dynamically attaches __typing_subst__ to late after parameters was already built, tuple_index(parameters, nparams, late) cannot find late in parameters and returns -1:

--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -525,8 +525,18 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
         }
         if (subst) {
             Py_ssize_t iparam = tuple_index(parameters, nparams, arg);
-            assert(iparam >= 0);
-            arg = PyObject_CallOneArg(subst, argitems[iparam]);
+            if (iparam < 0) {
+                // __parameters__ may be stale if an argument gained
+                // __typing_subst__ after the tuple was computed.
+                PyErr_Format(PyExc_TypeError,
+                             "argument %R with __typing_subst__ was not found "
+                             "in __parameters__",
+                             arg);
+                arg = NULL;
+            }
+            else {
+                arg = PyObject_CallOneArg(subst, argitems[iparam]);
+            }
             Py_DECREF(subst);
         }

In production CPython builds (NDEBUG), assert(iparam >= 0) is compiled out. _Py_subs_parameters() indexes argitems[-1] (the Py_ssize_t word sitting immediately before PyTupleObject.ob_item[0]) and passes that word as a PyObject * argument to the caller’s __typing_subst__ callback. On CPython >= 3.14, the field immediately preceding ob_item in PyTupleObject is ob_hash. Because tuple hashing over two integers is deterministic and invertible, a Jinja2 chat_template.jinja running inside ImmutableSandboxedEnvironment can:

  1. Read the memory address of a built-in C method or type from ''.maketrans.__repr__().
  2. Compute a 2-integer tuple (a, b) whose hash((a, b)) equals the target PyObject * address, use (a, b) as a dict key to populate ob_hash, and pass (a, b) as the substitution tuple to a generic alias (dict[str, ...]) constructed from standard sandbox objects.
  3. Receive the raw str, type, code, and function objects inside a Jinja macro callback and construct an arbitrary Python code object to execute OS commands inside the vLLM or inference server process.

Indicators of compromise (IOCs) and exploit signatures

  • Malicious Hugging Face tokenizer_config.json / chat_template.jinja patterns (gh-155752):
    • Jinja templates referencing __typing_prepare_subst__, __typing_subst__, __parameters__, or .maketrans inside macro definitions or namespace objects.
  • zlib <= 1.3.2 vulnerable call patterns:
    • C/C++ services calling gzwrite() + gzprintf() on non-blocking sockets/pipes (O_NONBLOCK), or calling inflateInit2(&strm, 0) followed by inflateReset() / inflateSync() and inflateGetDictionary().

Detection and remediation

# 1. Check installed and bundled zlib versions across Linux hosts and container images
ldconfig -p | rg libz\.so || true
python3 -c 'import zlib; print("python zlib:", zlib.ZLIB_VERSION, zlib.ZLIB_RUNTIME_VERSION)'

# 2. Scan downloaded Hugging Face model directories and tokenizer_config.json files
#    for GenericAlias substitution hooks in chat_template.jinja
rg -n '(__typing_subst__|__typing_prepare_subst__|__parameters__|maketrans)' \
  ~/.cache/huggingface/hub/ /models/ 2>/dev/null || true
  1. Upgrade zlib and minizip to 1.4: Rebuild or update native packages linking libz (>= 1.4) and replace any vendored contrib/minizip sources so CVE-2026-85091, THM-ZLIB-001, TOB-ZLIB-004..014, and block_central_name() are patched.
  2. Isolate Jinja2 chat_template evaluation and patch CPython if running BYOM inference: Because CPython is not backporting PR #155761 to Python 3.12 through 3.14, apply commit 3c9c477f508a (Objects/genericaliasobject.c) to custom Python builds used for multi-tenant LLM serving, reject untrusted chat_template files that reference dunder attributes (__*__), and run model-serving workers inside unprivileged sandboxes without cloud IAM or host secrets.

Timeline

  • 2026-08-13: RunSybil opens gh-155752 and python/cpython#155761 after CPython and Jinja maintainers decline to treat Python-level sandbox escapes as security vulnerabilities; CPython merges 3c9c477f508a onto main (3.15) without backporting to 3.12 through 3.14.
  • 2026-09-03 to 2026-11-03: CVE-2026-85091 (df84af25dc19), THM-ZLIB-001 (2fd31f00740e), TOB-ZLIB-004 (8179479c6274), 2804ba757385, and fd54d99ea361 land in madler/zlib.
  • 2026-11-03 to 2026-11-05: RunSybil publishes its 90-day disclosure on CPython GenericAlias chat-template RCE; Mark Adler tags zlib 1.4 (99623ef70973); and both disclosures are posted to oss-security (2026/11/05/10, 2026/11/05/11, and 2026/11/05/12).

From research to remediation

Check whether this pattern exists in your codebase

Turn this research into a remediation workflow. Use AI-native static analysis to find similar application vulnerabilities and generate review-ready fixes.

References