{"record":{"id":"c6939dc5f77d9f50","repo":"sgl-project/sglang","slug":"material-uri-has-invalid-base64-padding","errorCode":null,"errorMessage":"material URI has invalid base64 padding","messagePattern":"material URI has invalid 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":617,"sourceCode":"        batch,\n        condition_type=condition_type,\n        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","sourceCodeStart":599,"sourceCodeEnd":635,"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#L599-L635","documentation":"While scanning the inline base64 payload, more than two '=' padding characters were encountered. The strict streamer allows at most 2 trailing '=' per chunk.","triggerScenarios":"A material URI payload with '===' or padding characters repeated (e.g. payload built by naively concatenating independently-padded base64 segments).","commonSituations":"Joining multiple base64-encoded chunks each carrying their own padding; double-encoding; copy-paste duplicating '=' characters.","solutions":["Encode the whole payload once, unpadded, URL-safe: base64.urlsafe_b64encode(blob).rstrip(b'=')","If chunking is required, strip '=' from each chunk and pad only the final one","Regenerate the URI rather than hand-assembling it"],"exampleFix":"# before\npayload = \"\".join(base64.urlsafe_b64encode(c).decode() for c in chunks)  # each has '='\n# after\npayload = base64.urlsafe_b64encode(b\"\".join(chunks)).decode().rstrip('=')","handlingStrategy":"validation","validationCode":"payload = uri_payload\nassert payload.count(\"=\") <= 2 and payload.endswith(\"=\" * payload.count(\"=\")), \"bad padding\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Encode the entire payload once, strip padding with .rstrip('=')","Never concatenate separately-padded base64 chunks"],"tags":["minimax-h3","base64","padding","material-uri"],"backgroundTag":"invalid-base64-payload","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}