server: bound the last unbounded parses of untrusted text

Three ways in, each ending in a parse that bounds neither what it
builds nor how deep it nests:

videos.cpp read its multipart form fields with the raw parser, so a
512 MiB field of brackets died at the tree's teardown; the same file's
JSON path was bounded, so the form path now shares its gate, and a
field over budget or over depth reads as a bad parse (a form test pins
both refusals and a well-formed field).

Anthropic's buffered body parsed the model's tool-call arguments
directly; the streaming path already scans them with json_complete,
whose depth cap keeps a cooperating model from stack-killing the
worker, and the buffered body now passes the same gate, reading too
deep as an empty input.

The image decoders checked the container header's dimensions against
the pixel cap but converted whatever the bitstream actually decoded;
a container whose SPS disagrees with its header slipped through. Both
now re-check the decoded frame, as the video path already does. The
re-check is inside RAD_HAVE_FFMPEG and compiles with every FFmpeg
build; the media-less container proves the two server changes.
This commit is contained in:
fl0l0u authored and StillDeadcode committed 2026-10-31 07:50:43 +01:00
1 parent 546f0c2047
commit d54f3b9e6e
5 files changed
+77 -4

No files matched your search

+9 -2
View File
@@ -3989,8 +3989,15 @@ std::string anthropic_message_body(const OaiRequest& r, const ChoiceOut& c, cons
if (!r.continued.empty() && text.rfind(r.continued, 0) == 0) text.erase(0, r.continued.size());
if (!text.empty()) blocks.push_back(json{ { "type", "text" }, { "text", text } });
for (const ToolCall& tc : c.msg.tool_calls) {
json in = json::parse(tc.arguments, nullptr, false);
if (in.is_discarded() || !in.is_object()) in = json::object();
/* The same bound the streaming path applies: `arguments` is model output, and
* json_complete's depth-capped scan must run before nlohmann's recursion and its
* teardown, neither of which bounds depth on its own. Too deep or incomplete reads as
* an empty input, as a discarded parse did. */
json in = json::object();
if (json_complete(tc.arguments)) {
json v = json::parse(tc.arguments, nullptr, false);
if (!v.is_discarded() && v.is_object()) in = std::move(v);
}
blocks.push_back(json{ { "type", "tool_use" }, { "id", tc.id }, { "name", tc.name },
{ "input", in } });
}