{"record":{"id":"5f2b0e5481c14465","repo":"sgl-project/sglang","slug":"material-uri-has-data-after-base64-padding","errorCode":null,"errorMessage":"material URI has data after base64 padding","messagePattern":"material URI has data after base64 padding","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":619,"sourceCode":"        condition_index=condition_index,\n        media_type=media_type,\n    )\n    total = 0\n    encoded_size = 0\n    padding = 0\n    saw_padding = False\n    encoded_chunk = bytearray()\n    try:\n        with partial_path.open(\"wb\") as output:\n            for value in _iter_base64_payload_bytes(uri, payload_start):\n                encoded_size += 1\n                if value == ord(\"=\"):\n                    saw_padding = True\n                    padding += 1\n                    if padding > 2:\n                        raise ValueError(\"material URI has invalid base64 padding\")\n                elif saw_padding:\n                    raise ValueError(\"material URI has data after base64 padding\")\n                encoded_chunk.append(value)\n                if len(encoded_chunk) == MINIMAX_H3_BASE64_DECODE_CHUNK_CHARS:\n                    decoded_chunk = _decode_base64_chunk(encoded_chunk)\n                    total += len(decoded_chunk)\n                    output.write(decoded_chunk)\n                    encoded_chunk.clear()\n            if encoded_size == 0:\n                raise ValueError(\"material URI base64 payload is empty\")\n            if encoded_size % 4 == 1 or (padding and encoded_size % 4):\n                raise ValueError(\"material URI has an invalid base64 payload length\")\n            if encoded_chunk:\n                encoded_chunk.extend(b\"=\" * (-len(encoded_chunk) % 4))\n                decoded_chunk = _decode_base64_chunk(encoded_chunk)\n                total += len(decoded_chunk)\n                output.write(decoded_chunk)\n        decoded_size = (encoded_size * 3) // 4 - padding\n        if decoded_size <= 0:\n            raise ValueError(\"material URI decoded payload is empty\")","sourceCodeStart":601,"sourceCodeEnd":637,"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#L601-L637","documentation":"Raised while streaming a base64/data material URI for MiniMax H3: after one or more '=' padding characters were seen, a non-'=' base64 character followed. The strict streaming decoder only allows up to two trailing '=' chars at the very end of the payload.","triggerScenarios":"Calling minimax_h3_localize_material_uri with a data:/base64: URI whose base64 payload contains non-padding characters after '=' (e.g. 'aGVsbG8=9' or duplicated '=' mid-string).","commonSituations":"Hand-assembled or LLM-generated data URIs, string concatenation that appends query params after the padding, or trailing whitespace/CR-LF stripped incorrectly producing mid-payload '='.","solutions":["Inspect the payload after the final '=' and strip anything following it","Regenerate the data URI with base64.b64encode() instead of hand-editing","Validate with base64.b64decode(payload, validate=True) before submitting"],"exampleFix":"// before\nuri = f\"data:image/png;base64,{b64}=extra\"\n// after\nuri = f\"data:image/png;base64,{b64}\"","handlingStrategy":"validation","validationCode":"import base64\npayload = uri.split(',', 1)[1] if uri.startswith('data:') else uri.split(':', 1)[1]\nbase64.b64decode(payload, validate=True)  # raises on data after padding","typeGuard":null,"tryCatchPattern":"try:\n    path = minimax_h3_localize_material_uri(batch, uri, ...)\nexcept ValueError as e:\n    if 'base64' in str(e):\n        reject_request(f'bad material URI: {e}')","preventionTips":["Always build data URIs with base64.b64encode","Never append query strings after base64 padding","Run b64decode(validate=True) client-side first"],"tags":["base64","minimax-h3","material-uri","validation"],"backgroundTag":"invalid-base64-payload","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}