vendor: the pattern parser counts its nesting, and refuses past 64

A tool schema's `pattern` reaches the grammar converter as client data,
and the group scanner recursed once per nested '(': a few tens of KB of
brackets inside one JSON string was an uncatchable stack overflow of the
request worker. The body's depth and value bounds never saw it -- the
brackets are string content, not JSON nesting -- and 0003, the patch that
made this same function survive a hostile pattern, hardened the empty and
the looping cases but never the recursing one. It is the one remote crash
in the audit, and one request is the whole attack.

transform() now counts its nesting and records the refusal once, where
every unwinding frame met the same '(' and repeated it; check_errors turns
it into the clean throw the server already answers with a 400. Proven on
the compile host against the real converter: the 20000-group pattern is
refused by name, a 40-group pattern -- far past anything a real schema
nests -- still compiles. The record keeps the addition under 0003's name,
whose footing it stands on.
This commit is contained in:
fl0l0u committed 2026-11-15 20:38:09 +00:00
1 parent b83d53cf19
commit 2fda03ccdd
4 files changed
+46 -2

No files matched your search

+2 -2
View File
@@ -27,7 +27,7 @@ dee35610e7de346501f49a0f62bb9c99f9dc10534a22c0ee20baabf11fc61ca3 vendor/llama/c
fe5bb39af419fffc5291796848edc9f6d990c416ea8ff5fe602b9e4b8dd4140b vendor/llama/common/jinja/value.h
00a6eb892deb9c0578fec97e72b8dbb2518216bb325a972987691b67a14ecc02 vendor/llama/common/json-partial.cpp
1ff33e25293b376c9262c5e5842fcb50ebcf8f4e5c5222505a8a757be53fd4a5 vendor/llama/common/json-partial.h
a8743199b372fc75feb74b6441fbe860227751b0c379860f06a57e82953769bf vendor/llama/common/json-schema-to-grammar.cpp
c330c964ffc9f895c9d3c7050eb4a2372c9116c8aee85b4c6542952eb4134c35 vendor/llama/common/json-schema-to-grammar.cpp
e2e2d20d39e57ecf3c440df04097be4c6b3d59ba09f0655f675384d1c99f6801 vendor/llama/common/json-schema-to-grammar.h
d4b2739e4b06668dc14a1d3c6ed15c4fcb93d5c6e976f06bc3363e797fff9c1c vendor/llama/common/peg-parser.cpp
4e77267b71d77a5a5617d89a1cfb1e7b43df0af52e6ba38f305abfdf9f443464 vendor/llama/common/peg-parser.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
c06f36e9ccb21458ed37af649e00b143f7bc773e0c7623d4f19f49c7a15ecfe5 vendor/UPSTREAM
4e3fcc1f56d00c21967fa16e1d81aa9a012f1669c514ed16226204ff62e25d02 vendor/UPSTREAM
45e384d3d52c73cba3a64d6e6c25d47cd738cd8a55c30629e3201046eda62947 vendor/yyjson/LICENSE
d2d58ef0a3b2267862dc363832c4f3185fd375aea933d5d3419d1a940d6ece2e vendor/yyjson/yyjson.c
ef803cda5c06b8962face6dfa39c3284b3bcf3e73f4d7317664690cc779679ca vendor/yyjson/yyjson.h