{"record":{"id":"d7c30604e52d14fa","repo":"sgl-project/sglang","slug":"material-uri-has-an-invalid-base64-payload","errorCode":null,"errorMessage":"material URI has an invalid base64 payload","messagePattern":"material URI has an invalid base64 payload","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":586,"sourceCode":"\n\ndef _material_workdir(batch: Any) -> str:\n    registry = batch.extra.setdefault(MINIMAX_H3_TEMP_DIRS_EXTRA_KEY, {})\n    material_dirs = registry.get(\"material\")\n    if isinstance(material_dirs, list) and material_dirs:\n        return str(material_dirs[0])\n    return minimax_h3_register_temp_dir(\n        batch,\n        tempfile.mkdtemp(prefix=\"minimax_h3_material_\"),\n        owner=\"material\",\n    )\n\n\ndef _decode_base64_chunk(encoded: bytes | bytearray) -> bytes:\n    try:\n        return base64.b64decode(encoded, altchars=b\"-_\", validate=True)\n    except Exception as exc:\n        raise ValueError(\"material URI has an invalid base64 payload\") from exc\n\n\ndef _stream_base64_material(\n    batch: Any,\n    uri: str,\n    *,\n    condition_type: str,\n    condition_index: int,\n) -> str:\n    payload_start, media_type = _base64_uri_payload_start(uri)\n\n    output_path, partial_path = _material_output_paths(\n        batch,\n        condition_type=condition_type,\n        condition_index=condition_index,\n        media_type=media_type,\n    )\n    total = 0","sourceCodeStart":568,"sourceCodeEnd":604,"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#L568-L604","documentation":"A base64 chunk from a data-URI-style material failed strict decoding (b64decode with validate=True and URL-safe altchars '-_'). Any non-alphabet character, bad length, or malformed chunk triggers it.","triggerScenarios":"Inline base64 material URIs containing whitespace, '+'/'/' instead of '-_'/'_', truncated chunks, or concatenated payload with stray characters, streamed through _stream_base64_material in MINIMAX_H3_BASE64_DECODE_CHUNK_CHARS-sized chunks.","commonSituations":"Copy-paste corruption, URL-unsafe base64 not translated to the URL-safe alphabet, line-wrapped base64, or truncation from size limits.","solutions":["Re-encode with URL-safe alphabet, no padding/newlines: base64.urlsafe_b64encode(data).rstrip(b'=')","Strip whitespace/newlines from the payload before embedding","If standard base64, translate +/ to -_ before building the URI"],"exampleFix":"# before\nuri = \"data:application/octet-stream;base64,\" + std_b64  # may contain +/\n# after\nimport base64\nsafe = base64.urlsafe_b64encode(data).decode().rstrip('=')\nuri = \"data:application/octet-stream;base64,\" + safe","handlingStrategy":"validation","validationCode":"import base64\npayload = payload_part_of_uri\nclean = \"\".join(payload.split())  # strip whitespace\ntry:\n    base64.b64decode(clean + \"=\" * (-len(clean) % 4), altchars=b\"-_\", validate=True)\n    ok = True\nexcept Exception:\n    ok = False","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build URIs with base64.urlsafe_b64encode in one shot","Never paste line-wrapped base64 into URIs"],"tags":["minimax-h3","base64","material-uri","urlsafe"],"backgroundTag":"invalid-base64-payload","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}