vendor: the jinja engine budgets its nesting and its range()

A container's chat template is server-side attacker data the engine
parses and runs without any budget. The parser recursed once per nesting
block or paren: tens of KB of "{{ (((" or "{% if %}" in one
tokenizer.chat_template stack-overflowed whoever read it -- the
capability probe or the first render -- past every catch, and errors-
as-values cannot hold a stack overflow. And range() materialised one
array element per step: {{ range(4000000000) }} was an OOM per render.

Both entry points now share one 128-level guard whose throw is the same
exception class a malformed template already raises, and range() refuses
above 65536 values -- far past any template that exists, small enough
that the whole range stays transient. The refusals cross the ChatTemplate
seam as the error values the seam promises (a chat_test case pins that
both shapes refuse and that real nesting still renders). UPSTREAM keeps
the addition under the chat lift's record; the manifest re-hashes.
This commit is contained in:
fl0l0u committed 2026-11-15 20:38:09 +00:00
1 parent 2fda03ccdd
commit 7b9f33653f
6 files changed
+104 -4

No files matched your search

+4 -4
View File
@@ -15,15 +15,15 @@ bb12b9cc7940d6728304b6ae1d0d9c53637098f6df00119d4ba5ef7f186c385e vendor/llama/c
97866824d4dacfdeeb14839183e959d665ac766e12014f38e74610933a8b9cdc vendor/llama/common/jinja/caps.h
3d6774bc2dac477e10ddbee69eff403df36f5925c8512ccf8a249bde5c26dbd7 vendor/llama/common/jinja/lexer.cpp
93aecd72cc952fab08f657aa2a70e9f58421672b19d3179f8bdf555e683a1cc7 vendor/llama/common/jinja/lexer.h
284c3dcc92cfcbdb3391f4b251bdc2bd5191899973bf665e9351aca3b795c724 vendor/llama/common/jinja/parser.cpp
0f1c3902bd181634d9847e23ad360fdd4682777ea8c86b8267e1f87053e10025 vendor/llama/common/jinja/parser.cpp
6225eb759da910f3dd7753aed71c6938131cfa04c609d744e6f1390396422316 vendor/llama/common/jinja/parser.h
e3bfa255e10e81c756e1376740d752d6f73762233253f830dea2bcedd50f247f vendor/llama/common/jinja/README.md
dee35610e7de346501f49a0f62bb9c99f9dc10534a22c0ee20baabf11fc61ca3 vendor/llama/common/jinja/runtime.cpp
d422b8f5d41ac20ecdca451e69773156513cf461063013ad4515163f794b26a6 vendor/llama/common/jinja/runtime.cpp
427e1a8471394674b56c24c1946393b6c242481ffa49f3af396e6b257634a645 vendor/llama/common/jinja/runtime.h
1f7b1d6161c48a735853608849781736b69e526bf31549fc2cb692469f193715 vendor/llama/common/jinja/string.cpp
943ad34975e87c1a39570ac45238e2416cfb99530b53d853547c630198ea4b18 vendor/llama/common/jinja/string.h
61ae8bc57a7a551bdfb294a23a0ef8b5ba8e3cf4d695389f0f0797e2d7689781 vendor/llama/common/jinja/utils.h
9de5a424bc1339427800c3a22b708badd534bba2099ea35676a7e759a2a2cdb9 vendor/llama/common/jinja/value.cpp
4a5e8cec8a4c97f9e79689b09f1a224b4e2ffb16be3d540fa436a95bcfc10edc vendor/llama/common/jinja/value.cpp
fe5bb39af419fffc5291796848edc9f6d990c416ea8ff5fe602b9e4b8dd4140b vendor/llama/common/jinja/value.h
00a6eb892deb9c0578fec97e72b8dbb2518216bb325a972987691b67a14ecc02 vendor/llama/common/json-partial.cpp
1ff33e25293b376c9262c5e5842fcb50ebcf8f4e5c5222505a8a757be53fd4a5 vendor/llama/common/json-partial.h
@@ -50,7 +50,7 @@ d5104362705e687271807f499481db6033d85988e13fac12f36e370c6fce0551 vendor/shim/ll
5d556a22069133f7931850a13094d7390ba091051f0dc98cb1cfca824142a705 vendor/shim/llama_shim.cpp
628efd8a88524082c4736d3bc52790aa459b40728f213246c54550011f2754a2 vendor/shim/log.h
1c343ff2dbf801873acc2ee67c0e874137fb36df31421f36fc5cb6812463aae4 vendor/shim/ryml_impl.cpp
4e3fcc1f56d00c21967fa16e1d81aa9a012f1669c514ed16226204ff62e25d02 vendor/UPSTREAM
11bdda7f02eede804f1b4c56f8426def63d37a83e6484806567707b207b60dd6 vendor/UPSTREAM
45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947 vendor/yyjson/LICENSE
d2d58ef0a3b2267862dc363832c4f3185fd375aea933d5d3419d1a940d6ece2e vendor/yyjson/yyjson.c
ef803cda5c06b8962face6dfa39c3284b3bcf3e73f4d7317664690cc779679ca vendor/yyjson/yyjson.h