{"record":{"id":"e2d725902e4b5042","repo":"sgl-project/sglang","slug":"b64-format-hint-empty-data-payload","errorCode":null,"errorMessage":"{b64_format_hint} (empty data payload)","messagePattern":"(.+?) \\(empty data payload\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/image_io.py","lineNumber":22,"sourceCode":"import re\n\n\ndef save_base64_image_to_path(base64_data: str, target_path: str) -> str:\n    b64_format_hint = (\n        \"Failed to decode base64 image. \"\n        \"Expected format: `data:[<media-type>];base64,<data>`\"\n    )\n\n    match = re.match(r\"data:(.*?)(;base64)?,(.*)\", base64_data)\n    if not match:\n        raise ValueError(b64_format_hint)\n    media_type = match.group(1)\n    is_base64 = match.group(2)\n    if not is_base64:\n        raise ValueError(f\"{b64_format_hint} (missing ;base64 marker)\")\n    data = match.group(3)\n    if not data:\n        raise ValueError(f\"{b64_format_hint} (empty data payload)\")\n\n    if media_type.startswith(\"image/\"):\n        ext = media_type.split(\"/\")[-1].lower()\n        if ext == \"jpeg\":\n            ext = \"jpg\"\n    else:\n        ext = \"jpg\"\n    target_path = f\"{target_path}.{ext}\"\n    os.makedirs(os.path.dirname(target_path), exist_ok=True)\n\n    try:\n        image_data = base64.b64decode(data)\n    except Exception as exc:\n        raise Exception(f\"Failed to decode base64 image: {str(exc)}\") from exc\n\n    with open(target_path, \"wb\") as f:\n        f.write(image_data)\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/image_io.py#L4-L40","documentation":"The data URI parsed correctly but the payload after the comma is empty, so there is nothing to decode and write to disk. This usually indicates a truncated or placeholder image string.","triggerScenarios":"Passing data:image/png;base64, (nothing after the comma) via _maybe_url_image or prepare_warmup_image_path.","commonSituations":"Template placeholders, upstream truncation of the base64 string, string slicing bugs that drop the payload, empty image fields in request payloads treated as set.","solutions":["Check the producer side for truncation (log len(base64_data))","Treat empty payloads as missing images upstream instead of forwarding them"],"exampleFix":"// before\nsave_base64_image_to_path(\"data:image/png;base64,\", \"/tmp/img\")\n// after\nif payload:\n    save_base64_image_to_path(f\"data:image/png;base64,{payload}\", \"/tmp/img\")","handlingStrategy":"validation","validationCode":"def has_payload(uri: str) -> bool:\n    return uri.rsplit(\",\", 1)[-1].strip() != \"\"","typeGuard":null,"tryCatchPattern":"try:\n    save_base64_image_to_path(uri, path)\nexcept ValueError as e:\n    if \"empty data payload\" in str(e):\n        skip_image()  # treat as missing","preventionTips":["Treat empty image fields as absent upstream","Assert len(payload) > 0 before building requests"],"tags":["base64","data-uri","empty-payload","validation"],"backgroundTag":"malformed-base64-data-uri","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}