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:
zlib 1.4patchesCVE-2026-85091and 12 additional memory-safety and archive-extraction flaws: Released by Mark Adler on 4 to 5 November 2026,zlib 1.4fixes a heap buffer overflow ingzwrite.c(CVE-2026-85091/TOB-ZLIB-003, affecting1.3.1.2through1.3.2) whengzprintf()orgzvprintf()is called on a non-blocking descriptor after a write stall ingz_vacate(). The same release fixes an 8 MB out-of-bounds write past a caller’s 32 KB buffer ininflateGetDictionary()(THM-ZLIB-001, affecting1.3.1and1.3.2), a 1-byte window allocation overrun ininflateSync()(TOB-ZLIB-004), out-of-bounds reads/writes ininflatePrime()(TOB-ZLIB-014) anddeflatePrime()(TOB-ZLIB-013), uninitialized memory disclosure ininflateBack()andgzseek(), and arbitrary file write / directory traversal inminizip’sminiunzextractor.- Unbackported CPython
types.GenericAliasout-of-bounds read escapes Jinja2’sImmutableSandboxedEnvironmenton LLM inference servers: Disclosed by RunSybil on 3 November and relayed tooss-securityon 5 November,_Py_subs_parameters()inObjects/genericaliasobject.cassumed 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 evaluatesPyObject_CallOneArg(subst, argitems[-1]). On Python3.14+,argitems[-1]is the tuple’s cachedob_hashfield (Py_hash_t), letting a Jinja2 template craft a 2-integer tuple whose hash equals the memory address ofstr,type, orcode, forge a livePyObject*reference, and execute arbitrary OS commands when an inference engine such as vLLM renders a model’schat_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 Python3.12,3.13, or3.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
| Ecosystem | Component / Project | Identifier | Affected versions | Fixed version / Status | Vulnerable function & file |
|---|---|---|---|---|---|
| C / C++ | zlib (madler/zlib) | CVE-2026-85091 (TOB-ZLIB-003) | 1.3.1.2 through 1.3.2 | 1.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-014 | 1.3.1 and 1.3.2 (<= 1.3.2) | 1.4 | inflateGetDictionary() 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.2 | 1.4 | miniunz.c path traversal; block_central_name() double free; inftree9.c OOB pointer arithmetic |
| Python / C | CPython (python/cpython) | gh-155752 (PR #155761) | Python 3.12.x, 3.13.x, 3.14.x | Fixed on main (3.15+, commit c0006faf4f48); not backported to 3.12 to 3.14 | _Py_subs_parameters() in Objects/genericaliasobject.c |
| Python / AI | vLLM, Hugging Face transformers, and BYOM inference servers | RunSybil chat-template escape | Deployments rendering untrusted chat_template.jinja on unpatched CPython | Isolate inference workers at the container/VM boundary; restrict BYOM chat_template | Jinja2 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]):
- Reading
argitems[-1]therefore reads the substitution tuple’sob_hashfield and passes that 64-bit integer to the attacker’s__typing_subst__callback (a Jinja macro) as aPyObject*pointer. - 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 insideImmutableSandboxedEnvironment. - Because CPython’s tuple hash (xxHash-based
tuplehashover integer elements) is deterministic and invertible, the template computes two integers(a, b)whose tuple hash(a, b).__hash__()equals the address ofstr, caches the hash by using(a, b)as adictkey, and triggers theargitems[-1]read. - The Jinja macro receives a raw reference to the
strclass object, uses it to leak the addresses oftypeandcode(PyCode_Type), appliestype(range)(where Jinja’srangeis the Python functionsafe_range) to obtainFunctionType, constructs a bytecode object viacode(...), and executes arbitrary OS commands inside thevLLM/ 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
- Upgrade
zlibto>= 1.4: Rebuild or update systemzlib/libzpackages and static C/C++/Rust (libz-sys) builds that process untrusted gzip/zlib streams or useminizip. - Harden LLM inference servers (
vLLM, TGI, custom Jinja runners) againstchat_templateescapes:- Because CPython
3.12through3.14still contain the unpatched_Py_subs_parameters()out-of-bounds read, treat Jinja2’sSandboxedEnvironmentandImmutableSandboxedEnvironmentas non-security boundaries when evaluating untrusted templates. - Audit
tokenizer_config.jsonandchat_template.jinjafiles before loading third-party or user-uploaded models (specifically rejecting templates that referencemaketrans,dict[, or__typing_), and run model-serving workers inside locked-down containers or microVMs with no host filesystem mounts or cloud IAM credentials.
- Because CPython
Timeline
- 2026-08-13 to 2026-08-14: RunSybil reports
gh-155752and submits PR#155761(c0006faf4f48), fixing_Py_subs_parameters()in CPythonmain(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(d81c2d7eb705and6be4bcda3da1) andminizip/inflatememory bugs inmadler/zlib. - 2026-11-03: RunSybil publishes its technical analysis and
vLLMproof-of-concept for the CPythonGenericAliasJinja2 sandbox escape. - 2026-11-04 to 2026-11-05: Mark Adler releases
zlib 1.4; NVD publishesCVE-2026-85091; Alan Coopersmith posts both disclosures tooss-security(2026/11/05/10and2026/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
- madler/zlib v1.4 Release Notes (4-5 November 2026) and oss-security 2026/11/05/10
- madler/zlib commit d81c2d7eb705c62294ba03299255672078e89115 (Honor gzprintf's all-or-nothing-written contract when blocked, CVE-2026-85091)
- RunSybil Research (3 November 2026) and oss-security 2026/11/05/11: CPython 0-Day Vulnerabilities Threaten the AI Supply Chain
- python/cpython PR #155761 / commit c0006faf4f48f01126a8a0752da8f159142e410d (gh-155752: Do not crash when GenericAlias parameters change during substitution)