{"record":{"id":"d4a6b2a24660b795","repo":"Intervention/image","slug":"data-uri-contains-unsupported-image-type-d4a6b2","errorCode":null,"errorMessage":"Data Uri contains unsupported image type","messagePattern":"Data Uri contains unsupported image type","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/DataUriImageDecoder.php","lineNumber":46,"sourceCode":"    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if ($input instanceof DataUri) {\n            try {\n                return parent::decode($input->data());\n            } catch (DecoderException) {\n                throw new ImageDecoderException('Data Uri contains unsupported image type');\n            }\n        }\n\n        if (!is_string($input)) {\n            throw new InvalidArgumentException(\n                'Image source must be data uri scheme of type string or ' . DataUri::class,\n            );\n        }\n\n        try {\n            return parent::decode(DataUri::parse($input)->data());\n        } catch (DecoderException) {\n            throw new ImageDecoderException('Data Uri contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":63,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php#L28-L63","documentation":"Thrown by DataUriImageDecoder::decode() when the input is a DataUri object but decoding its embedded binary data fails — parent BinaryImageDecoder raised a DecoderException, remapped to this ImageDecoderException. The data URI structure was fine; the bytes behind it are not an image this ImageMagick can read.","triggerScenarios":"Passing a DataUri object to $manager->read() (or the decoder directly) whose media type/data is e.g. data:application/pdf, a data:image/svg+xml string without SVG delegates, or an image whose base64 body is truncated so the decoded bytes are unparseable.","commonSituations":"Accepting arbitrary data URIs from users (rich-text editors embed PDF icons, SVGs); SVG support differing between dev (with rsvg) and production (without); truncation of very long URIs by proxies or database column limits.","solutions":["Whelist media types before reading: only allow data:image/png, jpeg, gif, webp","For SVG support install the rsvg delegate or convert SVGs to raster before ingest","Catch ImageDecoderException and surface an 'unsupported image type' validation error"],"exampleFix":"// before: any DataUri accepted\n$image = $manager->read(DataUri::parse($input));\n\n// after: gate on media type\n$uri = DataUri::parse($input);\nif (!in_array($uri->mediaType(), ['image/png', 'image/jpeg', 'image/gif', 'image/webp'], true)) {\n    throw new InvalidArgumentException('Unsupported data URI media type');\n}\n$image = $manager->read($uri);","handlingStrategy":"try-catch","validationCode":"$uri = DataUri::parse((string) $input);\n$allowed = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];\nif (!in_array($uri->mediaType(), $allowed, true)) {\n    throw new InvalidArgumentException('data URI media type not allowed');\n}\n$image = $manager->read($uri);","typeGuard":"function isAllowedDataUri(DataUri $uri, array $allowed): bool\n{\n    return in_array($uri->mediaType(), $allowed, true);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\ImageDecoderException;\n\ntry {\n    $image = $manager->read($dataUri);\n} catch (ImageDecoderException $e) {\n    return back()->withErrors(['image' => 'data URI contains an unsupported image type']);\n}","preventionTips":["Allowlist data URI media types at the input boundary","Confirm SVG/raster delegate availability before accepting those MIME types","Reject data URIs whose decoded length looks truncated relative to expectations"],"tags":["data-uri","unsupported-format","decoding","validation"],"backgroundTag":"data-uri-unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}