sgl-project/sglang · error · ValueError
material URI has data after base64 padding
Error message
material URI has data after base64 padding
What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/material_io.py:619
condition_index=condition_index,
media_type=media_type,
)
total = 0
encoded_size = 0
padding = 0
saw_padding = False
encoded_chunk = bytearray()
try:
with partial_path.open("wb") as output:
for value in _iter_base64_payload_bytes(uri, payload_start):
encoded_size += 1
if value == ord("="):
saw_padding = True
padding += 1
if padding > 2:
raise ValueError("material URI has invalid base64 padding")
elif saw_padding:
raise ValueError("material URI has data after base64 padding")
encoded_chunk.append(value)
if len(encoded_chunk) == MINIMAX_H3_BASE64_DECODE_CHUNK_CHARS:
decoded_chunk = _decode_base64_chunk(encoded_chunk)
total += len(decoded_chunk)
output.write(decoded_chunk)
encoded_chunk.clear()
if encoded_size == 0:
raise ValueError("material URI base64 payload is empty")
if encoded_size % 4 == 1 or (padding and encoded_size % 4):
raise ValueError("material URI has an invalid base64 payload length")
if encoded_chunk:
encoded_chunk.extend(b"=" * (-len(encoded_chunk) % 4))
decoded_chunk = _decode_base64_chunk(encoded_chunk)
total += len(decoded_chunk)
output.write(decoded_chunk)
decoded_size = (encoded_size * 3) // 4 - padding
if decoded_size <= 0:
raise ValueError("material URI decoded payload is empty")View on GitHub (pinned to 0132848349)
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
Example fix
// before
uri = f"data:image/png;base64,{b64}=extra"
// after
uri = f"data:image/png;base64,{b64}" Defensive patterns
Strategy: validation
Validate before calling
import base64
payload = uri.split(',', 1)[1] if uri.startswith('data:') else uri.split(':', 1)[1]
base64.b64decode(payload, validate=True) # raises on data after padding Try / catch
try:
path = minimax_h3_localize_material_uri(batch, uri, ...)
except ValueError as e:
if 'base64' in str(e):
reject_request(f'bad material URI: {e}') Prevention
- Always build data URIs with base64.b64encode
- Never append query strings after base64 padding
- Run b64decode(validate=True) client-side first
When it happens
Trigger: 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).
Common situations: 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 '='.
Related errors
- tar material offset_data and size must be non-negative
- material URI has an invalid base64 payload
- material URI has invalid base64 padding
- condition URI must be a non-empty string
- No base64 image data found
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5f2b0e5481c14465.
Report an issue: GitHub.