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

+7
View File
@@ -277,6 +277,13 @@ value binary_expression::execute_impl(context & ctx) {
if (repeat <= 0) {
return res;
}
// RADIANCE: sibling of the range() cap in value.cpp -- repetition is the same
// attacker-template OOM, one append per step. "x" * 4000000000, and chained
// repetitions that pass a 64 MiB product at any step, are refused the way range()
// is: the same exception class, so errors-as-values carries it across the seam.
if (str.length() != 0 && repeat > (64ll << 20) / (int64_t)str.length()) {
throw raised_exception("string repetition would produce more than 67108864 bytes");
}
for (int64_t i = 0; i < repeat; ++i) {
res->val_str.append(str);
}