{"record":{"id":"1e3be54c66a50d49","repo":"Intervention/image","slug":"failed-to-decode-image-from-stream-could-be-unsup","errorCode":null,"errorMessage":"Failed to decode image from stream, could be unsupported image format","messagePattern":"Failed to decode image from stream, could be unsupported image format","errorType":"exception","errorClass":"ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/StreamImageDecoder.php","lineNumber":65,"sourceCode":"        $result = rewind($input);\n\n        if ($result === false) {\n            throw new StreamException('Failed to rewind position of stream');\n        }\n\n        while (!feof($input)) {\n            $chunk = fread($input, 1024);\n            if ($chunk === false) {\n                throw new StreamException('Failed to read image from stream');\n            }\n\n            $contents .= $chunk;\n        }\n\n        try {\n            return parent::decode($contents);\n        } catch (DecoderException) {\n            throw new ImageDecoderException(\n                'Failed to decode image from stream, could be unsupported image format',\n            );\n        }\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":71,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/StreamImageDecoder.php#L47-L71","documentation":"The stream was read fully into memory, but no decoder in the GD chain could interpret the bytes, so the generic DecoderException is rethrown as ImageDecoderException with the 'could be unsupported image format' hint. The problem is the content, not the stream handling.","triggerScenarios":"Streaming WebP or AVIF bytes into a GD build without that format support; binary garbage (archives, encrypted payloads) fed as an image stream; a truncated file that still finished reading.","commonSituations":"Microservices receiving image bytes over queues or sockets without MIME validation, GD builds missing webp on older distros, processing files by naming convention instead of sniffing content.","solutions":["Sniff the buffered content with (new finfo())->buffer($contents) before decoding","Check gd_info() for the required format support in that environment","Switch to the Imagick driver for broader format coverage","Catch ImageDecoderException and reject the source with a clear upstream error"],"exampleFix":"// before\n$image = $manager->decodeStream($socketStream);\n\n// after\n$contents = stream_get_contents($socketStream);\n$mime = (new finfo())->buffer($contents);\nif (!str_starts_with($mime, 'image/')) {\n    throw new RuntimeException('Stream did not contain an image: ' . $mime);\n}\n$image = $manager->read($contents);","handlingStrategy":"try-catch","validationCode":"$contents = stream_get_contents($fp);\nif (!str_starts_with((new finfo())->buffer($contents), 'image/')) {\n    throw new RuntimeException('Stream content is not an image');\n}\n$manager->read($contents);","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->decodeStream($fp);\n} catch (ImageDecoderException $e) {\n    // sniff buffered content, then reject or fall back to Imagick driver\n}","preventionTips":["Sniff bytes at trust boundaries (queues, sockets) before decoding","Know your GD build's supported formats via gd_info()","Keep an Imagick fallback for broader format coverage"],"tags":["stream","unsupported-format","gd","content-validation"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}