Archived
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:
1 parent
546f0c2047
commit
d54f3b9e6e
5 files changed
+77
-4
No files matched your search
@@ -3912,6 +3912,28 @@ TEST(messages_return_a_tool_call_as_a_tool_use_block) {
|
||||
CHECK(f.tmpl.last_n_tools == 1);
|
||||
}
|
||||
|
||||
/* `arguments` is model output, and the buffered body parses it behind the depth-capped scan
|
||||
* the streaming path applies: neither the recursive parse nor the tree's teardown bounds depth
|
||||
* on its own, and a model made to cooperate can name a tool and nest fifty thousand brackets.
|
||||
* Too deep reads as an empty input, as a discarded parse did; a shallow one rides whole. */
|
||||
TEST(messages_empty_a_tool_use_input_too_deep_to_parse) {
|
||||
OaiRequest r;
|
||||
r.id = "msg_test";
|
||||
r.model = "test-model";
|
||||
ChoiceOut c;
|
||||
UsageOut u;
|
||||
c.msg.tool_calls.push_back({ "call_1", "get_weather",
|
||||
"{\"city\":" + std::string(50000, '[') +
|
||||
std::string(50000, ']') + "}" });
|
||||
const json j = json::parse(anthropic_message_body(r, c, u));
|
||||
CHECK_EQ(j["content"][0]["type"].get<std::string>(), std::string("tool_use"));
|
||||
CHECK_EQ(j["content"][0]["name"].get<std::string>(), std::string("get_weather"));
|
||||
CHECK_EQ(j["content"][0]["input"].dump(), std::string("{}"));
|
||||
c.msg.tool_calls[0].arguments = "{\"city\":\"Paris\"}";
|
||||
const json k = json::parse(anthropic_message_body(r, c, u));
|
||||
CHECK_EQ(k["content"][0]["input"].dump(), std::string(R"({"city":"Paris"})"));
|
||||
}
|
||||
|
||||
TEST(messages_turns_a_tool_result_back_into_a_tool_message) {
|
||||
Fixture f;
|
||||
f.sched.reply = "sunny";
|
||||
|
||||
Reference in new issue
Block a user