HKUDS/Vibe-Trading · warning · FileSizeExceeded

decoded media exceeds {max_bytes} bytes

Error message

decoded media exceeds {max_bytes} bytes

What it means

After successful base64 decoding, save_base64_data_url enforces a size cap: if max_bytes is truthy and the decoded byte length exceeds it, FileSizeExceeded is raised with the limit in the message. This guards the host from decompressed-bomb style payloads before any bytes are written to disk.

Source

Thrown at agent/src/utils/media_decode.py:60

        FileSizeExceeded: If decoded data exceeds ``max_bytes``.
        ValueError: If the URL is malformed or uses an unsupported MIME type.
    """
    match = _DATA_URL_RE.match(data_url)
    if not match:
        raise ValueError("expected data:<mime>;base64,<payload>")
    mime = match.group(1).strip().lower()
    ext = _EXT_BY_MIME.get(mime)
    if not ext:
        raise ValueError(f"unsupported data URL MIME type: {mime}")

    payload = match.group(3).strip()
    try:
        decoded = base64.b64decode(payload, validate=True)
    except (binascii.Error, ValueError) as exc:
        raise ValueError("invalid base64 payload") from exc

    if max_bytes and len(decoded) > max_bytes:
        raise FileSizeExceeded(f"decoded media exceeds {max_bytes} bytes")

    output_dir.mkdir(parents=True, exist_ok=True)
    path = output_dir / f"{uuid.uuid4().hex}{ext}"
    path.write_bytes(decoded)
    return path

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Raise max_bytes in the call site if the limit is too strict for your use case
  2. Compress/resize media client-side before base64 encoding (e.g. downscale images)
  3. Catch FileSizeExceeded and surface a friendly 'attachment too large (max N bytes)' message
  4. Enforce the same limit client-side before upload to avoid wasted transfer

Example fix

# before
path = save_base64_data_url(data_url, out_dir, max_bytes=1_000_000)  # 1MB cap, 3MB image

# after
path = save_base64_data_url(data_url, out_dir, max_bytes=5_000_000)  # or resize image client-side
Defensive patterns

Strategy: try-catch

Validate before calling

import base64

def decoded_size_ok(data_url: str, max_bytes: int) -> bool:
    payload = data_url.split(",", 1)[1].strip() if "," in data_url else ""
    try:
        return len(base64.b64decode(payload, validate=True)) <= max_bytes
    except Exception:
        return False

Type guard

null

Try / catch

from agent.src.utils.media_decode import FileSizeExceeded

try:
    path = save_base64_data_url(data_url, out_dir, max_bytes=MAX_BYTES)
except FileSizeExceeded as e:
    return reject_attachment(f"attachment too large: {e}")

Prevention

When it happens

Trigger: Calling save_base64_data_url with a max_bytes limit smaller than the decoded asset size — e.g. a 10 MB photo decoded while max_bytes=5_000_000, or a client ignoring documented attachment limits.

Common situations: Users attaching high-resolution photos/screenshots to chat envelopes, configuration tightening the limit after large media already flowed, base64 hiding true size (~4/3 ratio) so request-body limits don't catch it, or a zip-bomb-like payload expanding hugely after decode.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/209b8d9af4a13f57. Report an issue: GitHub.