high

CVE

CVE-2026-85091, CVE-2026-4738

CWE

CWE-787, CWE-125, CWE-843, CWE-22

Affected Surface

  • C / C++ compression library `zlib` (`madler/zlib`) versions `< 1.4` (`1.3.1.2` through `1.3.2` for `CVE-2026-85091` in `gz_vacate()`; `1.3.1` and `1.3.2` for `inflateGetDictionary()` `THM-ZLIB-001`; plus `minizip` / `miniunz` and `contrib/infback9` `CVE-2026-4738`), fixed in `zlib 1.4`
  • CPython (`python/cpython`) versions `3.12.x`, `3.13.x`, and `3.14.x` (`Objects/genericaliasobject.c` `_Py_subs_parameters()` out-of-bounds read `argitems[-1]`, fixed on `main` in commit `c0006faf4f48` / PR `#155761` but not backported to `3.12` to `3.14` because CPython does not treat in-process Python sandboxes as a security boundary)
  • LLM inference engines and Bring-Your-Own-Model (BYOM) platforms (including `vLLM` and services evaluating untrusted Hugging Face `tokenizer_config.json` / `chat_template.jinja` templates inside Jinja2's `SandboxedEnvironment` or `ImmutableSandboxedEnvironment`)

TL;DR

On 4 and 5 November 2026 (oss-security 2026/11/05/10 and 2026/11/05/11), two low-level runtime disclosures highlighted memory-safety bugs in zlib and CPython:

  1. zlib 1.4 patches CVE-2026-85091 and 12 additional memory-safety and archive-extraction flaws: Released by Mark Adler on 4 to 5 November 2026, zlib 1.4 fixes a heap buffer overflow in gzwrite.c (CVE-2026-85091 / TOB-ZLIB-003, affecting 1.3.1.2 through 1.3.2) when gzprintf() or gzvprintf() is called on a non-blocking descriptor after a write stall in gz_vacate(). The same release fixes an 8 MB out-of-bounds write past a caller’s 32 KB buffer in inflateGetDictionary() (THM-ZLIB-001, affecting 1.3.1 and 1.3.2), a 1-byte window allocation overrun in inflateSync() (TOB-ZLIB-004), out-of-bounds reads/writes in inflatePrime() (TOB-ZLIB-014) and deflatePrime() (TOB-ZLIB-013), uninitialized memory disclosure in inflateBack() and gzseek(), and arbitrary file write / directory traversal in minizip’s miniunz extractor.
  2. Unbackported CPython types.GenericAlias out-of-bounds read escapes Jinja2’s ImmutableSandboxedEnvironment on LLM inference servers: Disclosed by RunSybil on 3 November and relayed to oss-security on 5 November, _Py_subs_parameters() in Objects/genericaliasobject.c assumed that every type argument carrying a __typing_subst__ hook was already present in the cached __parameters__ tuple. If a callback adds __typing_subst__ to a sibling parameter after __parameters__ is cached, tuple_index() returns -1, assert(iparam >= 0) is compiled out in release builds, and CPython evaluates PyObject_CallOneArg(subst, argitems[-1]). On Python 3.14+, argitems[-1] is the tuple’s cached ob_hash field (Py_hash_t), letting a Jinja2 template craft a 2-integer tuple whose hash equals the memory address of str, type, or code, forge a live PyObject* reference, and execute arbitrary OS commands when an inference engine such as vLLM renders a model’s chat_template.jinja. Because neither CPython nor Jinja2 considers in-process CPython memory bugs inside template sandboxes to be in scope for security backports, the fix (PR #155761) is not backported to Python 3.12, 3.13, or 3.14.

What to do now: Upgrade system and vendored zlib (and minizip) builds to 1.4 (noting the MSVC libz.dll library rename and z_off_t ABI restoration in the release notes). If you operate an LLM inference platform (vLLM, TGI, custom FastAPI/Jinja model runners) that accepts user-supplied or third-party Hugging Face models, do not rely on Jinja2’s ImmutableSandboxedEnvironment for isolation: disable custom Jinja chat templates on untrusted models, or isolate model/template evaluation inside an unprivileged container, gVisor/Firecracker sandbox, or separate OS process with no host credentials.

Affected components and versions

EcosystemComponent / ProjectIdentifierAffected versionsFixed version / StatusVulnerable function & file
C / C++zlib (madler/zlib)CVE-2026-85091 (TOB-ZLIB-003)1.3.1.2 through 1.3.21.4 (commit d81c2d7eb705)gzprintf(), gzvprintf(), and gz_vacate() in gzwrite.c
C / C++zlib (madler/zlib)THM-ZLIB-001, TOB-ZLIB-004, TOB-ZLIB-013, TOB-ZLIB-0141.3.1 and 1.3.2 (<= 1.3.2)1.4inflateGetDictionary() and inflateSync() in inflate.c; deflatePrime() in deflate.c
C / C++zlib (contrib/minizip & contrib/infback9)CVE-2026-4738 & Trail of Bits / Oculytic reports<= 1.3.21.4miniunz.c path traversal; block_central_name() double free; inftree9.c OOB pointer arithmetic
Python / CCPython (python/cpython)gh-155752 (PR #155761)Python 3.12.x, 3.13.x, 3.14.xFixed on main (3.15+, commit c0006faf4f48); not backported to 3.12 to 3.14_Py_subs_parameters() in Objects/genericaliasobject.c
Python / AIvLLM, Hugging Face transformers, and BYOM inference serversRunSybil chat-template escapeDeployments rendering untrusted chat_template.jinja on unpatched CPythonIsolate inference workers at the container/VM boundary; restrict BYOM chat_templateJinja2 ImmutableSandboxedEnvironment running on CPython

Technical analysis

1. zlib 1.4: CVE-2026-85091 (gzwrite.c) and inflateGetDictionary() 8 MB heap overrun

In zlib 1.3.1.2 through 1.3.2, gz_write() could temporarily point state->strm.next_in at a caller-supplied buffer during a non-blocking write stall (errno == EAGAIN / EWOULDBLOCK) and return before resetting next_in back to the internal state->in buffer. If the caller subsequently invoked gzprintf() or gzvprintf(), formatted bytes were appended to state->in (strm->avail_in += len; state->x.pos += len) and then flushed via gz_vacate(state).

When gz_vacate() stalled again or calculated the remaining bytes to memmove() using the stale strm->next_in pointer, gzprintf() failed to roll back strm->avail_in and state->x.pos, corrupting the buffer accounting and overflowing state->in. Commit d81c2d7eb705 (paired with 6be4bcda3da1) restores state->strm.next_in = state->in after gz_write() and discards unwritten formatted output whenever gz_vacate() stalls:

--- a/gzwrite.c
+++ b/gzwrite.c
@@ -259,6 +259,7 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
                 return state->again ? put - len : 0;
             }
         } while (len);
+        state->strm.next_in = state->in;
     }
...
@@ -483,6 +483,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;
+    }

Equally important for network services and archive parsers, zlib 1.4 fixes THM-ZLIB-001 in inflateGetDictionary() (affecting 1.3.1 and 1.3.2), where feeding a zlib header with an invalid window size followed by inflateReset() or inflateSync() caused inflateGetDictionary() to copy up to 8 MB past the caller’s 32 KB dictionary buffer, and TOB-ZLIB-004, where calling inflateSync() before the window size was known allocated a 1-byte sliding window that subsequent decompression overran.

2. CPython _Py_subs_parameters() argitems[-1] out-of-bounds read and Jinja2 chat-template escape

When an LLM serving platform (such as vLLM or transformers apply_chat_template()) formats a prompt for a model downloaded from Hugging Face, it evaluates the model’s chat_template (tokenizer_config.json or chat_template.jinja) inside Jinja2’s ImmutableSandboxedEnvironment. That sandbox blocks private/dunder attributes (__class__, __subclasses__, __globals__), leaving only basic built-in types (dict, str, int, tuple, range).

However, Python’s subscript operator dict[a, b] constructs a types.GenericAlias object in C (Objects/genericaliasobject.c) without touching any blocked attribute. When a GenericAlias is first created or inspected, CPython scans its arguments for objects that define __typing_subst__ and caches those parameters in alias->parameters (__parameters__). Later, when the alias is subscripted (alias[x]), _Py_subs_parameters() first runs any __typing_prepare_subst__ hooks on the arguments and then substitutes each argument that now has __typing_subst__:

--- 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);
         }

Before commit c0006faf4f48, if an argument late did not have __typing_subst__ when alias.__parameters__ was cached, and a callback added __typing_subst__ to late during substitution, tuple_index(parameters, nparams, late) returned -1. Because assert(iparam >= 0) is compiled out under -DNDEBUG in production Python builds, CPython called PyObject_CallOneArg(subst, argitems[-1]).

In CPython 3.14, PyTupleObject stores its cached 64-bit hash (ob_hash) immediately before ob_item[0] (argitems[0]):

  1. Reading argitems[-1] therefore reads the substitution tuple’s ob_hash field and passes that 64-bit integer to the attacker’s __typing_subst__ callback (a Jinja macro) as a PyObject* pointer.
  2. The template first leaks the live address of &PyUnicode_Type (str) from the string representation of ''.maketrans (<built-in method maketrans of type object at 0x...>), which is accessible inside ImmutableSandboxedEnvironment.
  3. Because CPython’s tuple hash (xxHash-based tuplehash over integer elements) is deterministic and invertible, the template computes two integers (a, b) whose tuple hash (a, b).__hash__() equals the address of str, caches the hash by using (a, b) as a dict key, and triggers the argitems[-1] read.
  4. The Jinja macro receives a raw reference to the str class object, uses it to leak the addresses of type and code (PyCode_Type), applies type(range) (where Jinja’s range is the Python function safe_range) to obtain FunctionType, constructs a bytecode object via code(...), and executes arbitrary OS commands inside the vLLM / inference server process.

Detection and remediation

# 1. Check system and Python-linked zlib versions (< 1.4 is affected by CVE-2026-85091 / THM-ZLIB-001)
python3 -c 'import zlib; print("zlib runtime:", zlib.ZLIB_RUNTIME_VERSION, "compiled:", zlib.ZLIB_VERSION)'
pkg-config --modversion zlib 2>/dev/null || true

# 2. Scan Hugging Face model directories and caches for suspicious chat_template definitions
rg -n 'maketrans|__typing_subst__|__typing_prepare_subst__|__parameters__' \
  ~/.cache/huggingface/ /models/ --glob '*.{json,jinja}' 2>/dev/null || true
  1. Upgrade zlib to >= 1.4: Rebuild or update system zlib / libz packages and static C/C++/Rust (libz-sys) builds that process untrusted gzip/zlib streams or use minizip.
  2. Harden LLM inference servers (vLLM, TGI, custom Jinja runners) against chat_template escapes:
    • Because CPython 3.12 through 3.14 still contain the unpatched _Py_subs_parameters() out-of-bounds read, treat Jinja2’s SandboxedEnvironment and ImmutableSandboxedEnvironment as non-security boundaries when evaluating untrusted templates.
    • Audit tokenizer_config.json and chat_template.jinja files before loading third-party or user-uploaded models (specifically rejecting templates that reference maketrans, dict[, or __typing_), and run model-serving workers inside locked-down containers or microVMs with no host filesystem mounts or cloud IAM credentials.

Timeline

  • 2026-08-13 to 2026-08-14: RunSybil reports gh-155752 and submits PR #155761 (c0006faf4f48), fixing _Py_subs_parameters() in CPython main (3.15+); CPython declines security backports under its policy that Python in-process sandboxes are not a supported security boundary.
  • 2026-09-17 to 2026-10-26: Mark Adler commits fixes for CVE-2026-85091 (d81c2d7eb705 and 6be4bcda3da1) and minizip / inflate memory bugs in madler/zlib.
  • 2026-11-03: RunSybil publishes its technical analysis and vLLM proof-of-concept for the CPython GenericAlias Jinja2 sandbox escape.
  • 2026-11-04 to 2026-11-05: Mark Adler releases zlib 1.4; NVD publishes CVE-2026-85091; Alan Coopersmith posts both disclosures to oss-security (2026/11/05/10 and 2026/11/05/11).

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