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
@@ -327,6 +327,12 @@ int decode_image(const uint8_t* data, size_t n, int64_t max_pixels, Frame* out,
|
||||
SwsContext* sws = nullptr;
|
||||
bool got = false;
|
||||
const int s = decode_frames(in, [&](int64_t, const AVFrame* f) -> int {
|
||||
/* The decoded frame, not the header's size, is what gets converted: a container whose
|
||||
* bitstream disagrees with its declared dimensions must not slip past the cap. */
|
||||
if ((int64_t)f->width * f->height > max_pixels) {
|
||||
*why = "the decoded image is larger than the server's pixel limit";
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
const int c = to_rgb(f, &sws, out, why);
|
||||
if (c < 0) return c;
|
||||
got = true;
|
||||
@@ -355,6 +361,12 @@ int decode_image_rgba(const uint8_t* data, size_t n, int64_t max_pixels, FrameRG
|
||||
SwsContext* sws = nullptr;
|
||||
bool got = false;
|
||||
const int s = decode_frames(in, [&](int64_t, const AVFrame* f) -> int {
|
||||
/* Re-check the decoded frame against the cap, as decode_image and the video path do:
|
||||
* the bitstream, not the header, decides what the converter allocates. */
|
||||
if ((int64_t)f->width * f->height > max_pixels) {
|
||||
*why = "the decoded image is larger than the server's pixel limit";
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
const int c = to_rgba(f, &sws, out, why);
|
||||
if (c < 0) return c;
|
||||
got = true;
|
||||
|
||||
Reference in new issue
Block a user