{"record":{"id":"ff4b7f7135ef4997","repo":"sgl-project/sglang","slug":"material-uri-has-an-invalid-base64-payload-length","errorCode":null,"errorMessage":"material URI has an invalid base64 payload length","messagePattern":"material URI has an invalid base64 payload length","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":629,"sourceCode":"            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\")\n        if total != decoded_size:\n            raise ValueError(\n                f\"MiniMax H3 base64 decoded size {total} != expected {decoded_size}\"\n            )\n        partial_path.replace(output_path)\n    except Exception:\n        partial_path.unlink(missing_ok=True)\n        output_path.unlink(missing_ok=True)\n        raise\n    return str(output_path)","sourceCodeStart":611,"sourceCodeEnd":647,"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#L611-L647","documentation":"The base64 payload length is invalid: either len % 4 == 1 (cannot be valid base64 at all) or padding was present but the total length was not a multiple of 4. The strict decoder refuses such payloads.","triggerScenarios":"A data/base64 URI whose payload length mod 4 is 1 (e.g. 5 chars), or payload with '=' padding but length not divisible by 4 (e.g. 'AAAAA=').","commonSituations":"Character loss from copy/paste truncation, URL-unescaping that removed chars, or padding stripped by a URL-safe encoder without re-adding it.","solutions":["Re-encode the source bytes with base64.b64encode to get canonical padding","If using base64.urlsafe_b64encode output in a URL, keep the '=' chars escaped as %3D","Check payload length % 4 == 0 client-side before submission"],"exampleFix":"# before\npayload = b64.rstrip('=')  # padding no longer consistent\n# after\npayload = b64  # keep exact b64encode output","handlingStrategy":"validation","validationCode":"assert len(payload) % 4 != 1 and (not payload.endswith('=') or len(payload) % 4 == 0), 'bad b64 length'","typeGuard":null,"tryCatchPattern":"except ValueError as e: report malformed base64 URI to caller","preventionTips":["Keep canonical b64encode output","URL-escape '=' as %3D inside URLs"],"tags":["base64","length-validation","minimax-h3"],"backgroundTag":"invalid-base64-payload","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}