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
@@ -368,6 +368,34 @@ TEST(a_form_creates_a_video_too) {
|
||||
CHECK_EQ(v.f->srv->router().dispatch(q).status, 400);
|
||||
}
|
||||
|
||||
/* A form field that carries JSON is parsed under a value budget and a depth cap, like every
|
||||
* other untrusted text: a field of brackets alone sits well inside the body cap and would take
|
||||
* the worker down at the deep tree's teardown. Over-deep and over-budget read as a bad parse. */
|
||||
TEST(a_form_field_of_brackets_is_refused_rather_than_parsed) {
|
||||
Videos v;
|
||||
const std::string deep = std::string(4096, '[');
|
||||
for (const char* field : { "target", "conditions", "loras" }) {
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a boat" }, FormPart{ field, "", "", deep } };
|
||||
CHECK_EQ(v.f->srv->router().dispatch(q).status, 400);
|
||||
}
|
||||
/* Over the value budget but shallow, on the same gate. */
|
||||
std::string wide = "[";
|
||||
for (int i = 0; i < (1 << 20) + 2; ++i) wide += (i ? "," : "") + std::string("1");
|
||||
wide += "]";
|
||||
HttpRequest q;
|
||||
q.method = "POST";
|
||||
q.path = "/v1/videos";
|
||||
q.form = { FormPart{ "prompt", "", "", "a boat" }, FormPart{ "target", "", "", wide } };
|
||||
CHECK_EQ(v.f->srv->router().dispatch(q).status, 400);
|
||||
/* And a well-formed one still parses: it reaches the schema, not the parse refusal. */
|
||||
q.form = { FormPart{ "prompt", "", "", "a boat" },
|
||||
FormPart{ "target", "", "", "{\"short_edge\":256}" } };
|
||||
CHECK_EQ(v.f->srv->router().dispatch(q).status, 200);
|
||||
}
|
||||
|
||||
/* The job's life: queued at once, completed with progress 100 and an expiry, the MP4 and its
|
||||
* first frame served; listing it, deleting it, and a 404 after. */
|
||||
TEST(a_video_job_completes_and_serves_its_file) {
|
||||
|
||||
Reference in new issue
Block a user