Skip to content

fix(agent): reject oversized base64 images before decoding to prevent OOM - #2779

Closed
dieutx wants to merge 1 commit into
NousResearch:mainfrom
dieutx:fix/base64-image-size-limit
Closed

fix(agent): reject oversized base64 images before decoding to prevent OOM#2779
dieutx wants to merge 1 commit into
NousResearch:mainfrom
dieutx:fix/base64-image-size-limit

Conversation

@dieutx

@dieutx dieutx commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • _save_anthropic_image_to_temp() calls base64.b64decode(data) with no size check
  • A large base64 payload decodes fully into memory before writing to disk
  • Fix: check base64 string length before decoding, reject if over 50MB (~37.5MB decoded)

How to reproduce

  • Send an inline base64 image > 50MB in a message
  • The entire payload is decoded into memory before any write

How to test

  • The check is a simple length comparison before the decode call
  • Normal images (< 50MB base64) are unaffected

Platform tested

  • Linux, hermes-agent v0.4.0

… OOM

base64.b64decode() is called on inline image data with no size check.
A maliciously large base64 payload (e.g., 500MB) would decode fully
into memory before writing to disk, potentially causing OOM.

Add a 50MB base64 length check (~37.5MB decoded) before decoding.
@dieutx dieutx closed this Mar 24, 2026
@dieutx dieutx reopened this Mar 24, 2026
@dieutx dieutx closed this Mar 24, 2026
@dieutx dieutx reopened this Mar 24, 2026
@dieutx

dieutx commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing — #2690 adds comprehensive image size limits (20MB pre-check + post-download) across all image entry points, which covers the OOM prevention this was targeting. The base64 decode path in run_agent.py is a slightly different entry point, but not worth a separate PR given #2690's broader coverage.

@dieutx dieutx closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant