{"record":{"id":"d721a3b1b890c59d","repo":"Intervention/image","slug":"input-is-not-valid-base64-encoded-data","errorCode":null,"errorMessage":"Input is not valid Base64-encoded data","messagePattern":"Input is not valid Base64-encoded data","errorType":"exception","errorClass":"DecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/AbstractDecoder.php","lineNumber":89,"sourceCode":"\n    /**\n     * Decodes given base64 encoded data.\n     *\n     * @throws InvalidArgumentException\n     * @throws DecoderException\n     */\n    protected function decodeBase64Data(mixed $input): string\n    {\n        if (!is_string($input) && !$input instanceof Stringable) {\n            throw new InvalidArgumentException(\n                'Base64-encoded data must be either of type string or instance of Stringable',\n            );\n        }\n\n        $decoded = base64_decode((string) $input, true);\n\n        if ($decoded === false) {\n            throw new DecoderException('Input is not valid Base64-encoded data');\n        }\n\n        if (base64_encode($decoded) !== str_replace([\"\\n\", \"\\r\"], '', (string) $input)) {\n            throw new DecoderException('Input is not valid Base64-encoded data');\n        }\n\n        return $decoded;\n    }\n}\n","sourceCodeStart":71,"sourceCodeEnd":99,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/AbstractDecoder.php#L71-L99","documentation":"base64_decode() in strict mode returned false: the input contains characters outside the standard Base64 alphabet, so it cannot be decoded at all. This is the character-level check; the separate round-trip check (error 89) catches structurally invalid but decodable input.","triggerScenarios":"Base64 payloads using the URL-safe alphabet ('-' and '_' instead of '+' and '/'), a leftover 'data:image/png;base64,' prefix inside the payload, or binary garbage passed as base64.","commonSituations":"Frontends or microservices encoding with base64url (JWT-style encoders); concatenating the data-URI prefix with an already-prefixed string; mojibake from unescaped transport.","solutions":["Strip any 'data:...;base64,' prefix so only the raw base64 payload remains","Convert base64url to standard base64: str_replace(['-','_'], ['+','/'], $v) and re-pad with '='","Regenerate the payload with standard base64 (e.g. PHP base64_encode or JS btoa) on the producing side"],"exampleFix":"// before\n$image = $manager->read($base64urlString);\n\n// after\n$std = str_replace(['-', '_'], ['+', '/'], $base64urlString);\n$std .= str_repeat('=', (4 - strlen($std) % 4) % 4);\n$image = $manager->read($std);","handlingStrategy":"validation","validationCode":"$payload = preg_replace('#^data:[^,]+,#', '', $input); // strip data-uri prefix\n$payload = str_replace(['-', '_'], ['+', '/'], $payload); // base64url -> base64\nif (base64_decode($payload, true) === false) {\n    throw new \\RuntimeException('Not valid base64');\n}","typeGuard":"function looksLikeBase64(string $value): bool\n{\n    return preg_match('/^[A-Za-z0-9+\\/=\\r\\n]+$/', $value) === 1;\n}","tryCatchPattern":"try {\n    $image = $manager->read($payload);\n} catch (DecoderException $e) {\n    // invalid base64 - reject or re-request the source file\n}","preventionTips":["Strip data-URI prefixes before passing raw base64","Normalize base64url to standard base64 on the receiving side","Produce payloads with standard base64 encoders"],"tags":["base64","decoding","input-validation"],"backgroundTag":"invalid-base64","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}