Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions environments/tool_call_parsers/hermes_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def parse(self, text: str) -> ParseResult:
continue

tc_data = json.loads(raw_json)
if "name" not in tc_data:
continue
tool_calls.append(
ChatCompletionMessageToolCall(
id=f"call_{uuid.uuid4().hex[:8]}",
Expand Down
2 changes: 2 additions & 0 deletions environments/tool_call_parsers/mistral_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def parse(self, text: str) -> ParseResult:
parsed = [parsed]

for tc in parsed:
if "name" not in tc:
continue
args = tc.get("arguments", {})
if isinstance(args, dict):
args = json.dumps(args, ensure_ascii=False)
Expand Down
20 changes: 18 additions & 2 deletions tools/vision_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def _resolve_download_timeout() -> float:

_VISION_DOWNLOAD_TIMEOUT = _resolve_download_timeout()

# Hard cap on downloaded image file size (50 MB). Prevents OOM from
# attacker-hosted multi-gigabyte files or decompression bombs.
_VISION_MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024


def _validate_image_url(url: str) -> bool:
"""
Expand Down Expand Up @@ -181,13 +185,25 @@ async def _ssrf_redirect_guard(response):
)
response.raise_for_status()

# Reject overly large images early via Content-Length header.
cl = response.headers.get("content-length")
if cl and int(cl) > _VISION_MAX_DOWNLOAD_BYTES:
raise ValueError(
f"Image too large ({int(cl)} bytes, max {_VISION_MAX_DOWNLOAD_BYTES})"
)

final_url = str(response.url)
blocked = check_website_access(final_url)
if blocked:
raise PermissionError(blocked["message"])

# Save the image content
destination.write_bytes(response.content)
# Save the image content (double-check actual size)
body = response.content
if len(body) > _VISION_MAX_DOWNLOAD_BYTES:
raise ValueError(
f"Image too large ({len(body)} bytes, max {_VISION_MAX_DOWNLOAD_BYTES})"
)
destination.write_bytes(body)

return destination
except Exception as e:
Expand Down
Loading