{"record":{"id":"0c8e751118400020","repo":"sgl-project/sglang","slug":"data-uri-must-use-base64-encoding","errorCode":null,"errorMessage":"data URI must use ;base64 encoding","messagePattern":"data URI must use ;base64 encoding","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/material_io.py","lineNumber":102,"sourceCode":"                    shutil.rmtree(str(path), ignore_errors=True)\n        if not registry:\n            batch.extra.pop(MINIMAX_H3_TEMP_DIRS_EXTRA_KEY, None)\n    if owners is None or \"material\" in selected:\n        batch.extra.pop(MINIMAX_H3_MATERIAL_CACHE_EXTRA_KEY, None)\n        batch.extra.pop(MINIMAX_H3_MATERIAL_PROBE_EXTRA_KEY, None)\n\n\ndef _base64_uri_payload_start(uri: str) -> tuple[int, str | None]:\n    media_type = None\n    if uri.startswith(\"data:\"):\n        separator = uri.find(\",\")\n        if separator < 0:\n            raise ValueError(\"data URI must contain a comma separator\")\n        if separator > MINIMAX_H3_BASE64_HEADER_MAX_CHARS:\n            raise ValueError(\"data URI header is too large\")\n        header = uri[:separator]\n        if \";base64\" not in header:\n            raise ValueError(\"data URI must use ;base64 encoding\")\n        media_type = header[5:].split(\";\", 1)[0].lower() or None\n        payload_start = separator + 1\n    elif uri.startswith(\"base64://\"):\n        payload_start = len(\"base64://\")\n        separator = uri.find(\",\", payload_start)\n        if separator >= 0:\n            if separator - payload_start > MINIMAX_H3_BASE64_HEADER_MAX_CHARS:\n                raise ValueError(\"base64 URI header is too large\")\n            header = uri[payload_start:separator]\n            media_type = header.split(\";\", 1)[0].lower() or None\n            payload_start = separator + 1\n    else:  # pragma: no cover - guarded by the caller\n        raise ValueError(\"not a base64 material URI\")\n    return payload_start, media_type\n\n\ndef _iter_base64_payload_bytes(uri: str, payload_start: int):\n    \"\"\"Yield validated, unquoted base64 bytes without copying the payload.\"\"\"","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/material_io.py#L84-L120","documentation":"The data-URI header parsed from a 'data:' material URI must contain the ';base64' marker, because the loader only decodes base64 payloads (not percent-encoded or plain-text data URIs). Without it the payload encoding is ambiguous and decoding would corrupt the material.","triggerScenarios":"Passing URIs like 'data:image/png,<percent-encoded-bytes>' or 'data:text/plain,hello' to _stream_base64_material.","commonSituations":"Using HTML-style inline data URIs (which permit other encodings), LLM-generated URIs omitting the ;base64 parameter, or converting URLs from another format without adding the marker.","solutions":["Emit ';base64' in the header: 'data:image/png;base64,<payload>'","If the source is raw bytes, base64-encode them before building the URI","Pre-validate that ';base64' appears before the first comma in the URI"],"exampleFix":"// before\nuri = f\"data:image/png,{quote(png_bytes)}\"\n// after\nuri = \"data:image/png;base64,\" + base64.b64encode(png_bytes).decode('ascii')","handlingStrategy":"validation","validationCode":"if uri.startswith('data:'):\n    header = uri.split(',', 1)[0]\n    assert ';base64' in header, 'data URI must declare ;base64'","typeGuard":"def is_base64_data_uri(uri: str) -> bool:\n    return uri.startswith('data:') and ';base64' in uri.split(',', 1)[0]","tryCatchPattern":null,"preventionTips":["Always emit ';base64' in generated URIs","Reject other data-URI encodings at admission"],"tags":["minimax-h3","data-uri","base64","material-io"],"backgroundTag":"malformed-data-uri","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}