{"record":{"id":"209b8d9af4a13f57","repo":"HKUDS/Vibe-Trading","slug":"decoded-media-exceeds-max-bytes-bytes","errorCode":null,"errorMessage":"decoded media exceeds {max_bytes} bytes","messagePattern":"decoded media exceeds (.+?) bytes","errorType":"exception","errorClass":"FileSizeExceeded","httpStatus":null,"severity":"warning","filePath":"agent/src/utils/media_decode.py","lineNumber":60,"sourceCode":"        FileSizeExceeded: If decoded data exceeds ``max_bytes``.\n        ValueError: If the URL is malformed or uses an unsupported MIME type.\n    \"\"\"\n    match = _DATA_URL_RE.match(data_url)\n    if not match:\n        raise ValueError(\"expected data:<mime>;base64,<payload>\")\n    mime = match.group(1).strip().lower()\n    ext = _EXT_BY_MIME.get(mime)\n    if not ext:\n        raise ValueError(f\"unsupported data URL MIME type: {mime}\")\n\n    payload = match.group(3).strip()\n    try:\n        decoded = base64.b64decode(payload, validate=True)\n    except (binascii.Error, ValueError) as exc:\n        raise ValueError(\"invalid base64 payload\") from exc\n\n    if max_bytes and len(decoded) > max_bytes:\n        raise FileSizeExceeded(f\"decoded media exceeds {max_bytes} bytes\")\n\n    output_dir.mkdir(parents=True, exist_ok=True)\n    path = output_dir / f\"{uuid.uuid4().hex}{ext}\"\n    path.write_bytes(decoded)\n    return path\n","sourceCodeStart":42,"sourceCodeEnd":66,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/utils/media_decode.py#L42-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Raise max_bytes in the call site if the limit is too strict for your use case","Compress/resize media client-side before base64 encoding (e.g. downscale images)","Catch FileSizeExceeded and surface a friendly 'attachment too large (max N bytes)' message","Enforce the same limit client-side before upload to avoid wasted transfer"],"exampleFix":"# before\npath = save_base64_data_url(data_url, out_dir, max_bytes=1_000_000)  # 1MB cap, 3MB image\n\n# after\npath = save_base64_data_url(data_url, out_dir, max_bytes=5_000_000)  # or resize image client-side","handlingStrategy":"try-catch","validationCode":"import base64\n\ndef decoded_size_ok(data_url: str, max_bytes: int) -> bool:\n    payload = data_url.split(\",\", 1)[1].strip() if \",\" in data_url else \"\"\n    try:\n        return len(base64.b64decode(payload, validate=True)) <= max_bytes\n    except Exception:\n        return False","typeGuard":"null","tryCatchPattern":"from agent.src.utils.media_decode import FileSizeExceeded\n\ntry:\n    path = save_base64_data_url(data_url, out_dir, max_bytes=MAX_BYTES)\nexcept FileSizeExceeded as e:\n    return reject_attachment(f\"attachment too large: {e}\")","preventionTips":["Enforce the same max size client-side before encoding to save bandwidth","Compress/downscale images before base64 encoding","Keep the limit in shared config so frontend and backend never diverge"],"tags":["file-size","limit","media","upload"],"backgroundTag":"payload-too-large","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}