{"record":{"id":"aa4eceb28f1fbe00","repo":"Intervention/image","slug":"failed-to-decode-image-from-stream-could-be-unsup-aa4ece","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/Imagick/Decoders/StreamImageDecoder.php","lineNumber":61,"sourceCode":"        $contents = '';\n        $rewind = rewind($input);\n        if ($rewind === 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":43,"sourceCodeEnd":67,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/StreamImageDecoder.php#L43-L67","documentation":"The stream was drained successfully but its bytes failed to decode in BinaryImageDecoder (Imagick::readImageBlob). Root causes are identical to reading binary data directly; the message already guesses 'unsupported image format', but truncated content is equally common. The original DecoderException is discarded, so no detail survives.","triggerScenarios":"ImageManager::read(fopen($path, 'rb')) where the file is corrupt or the format lacks a delegate; reading php://input when the request body is only partially uploaded; stream wrappers over remote resources returning error pages.","commonSituations":"Upload endpoints streaming request bodies straight into the manager; WebP/AVIF sources on hosts without delegates; interrupted transfers leaving short bodies.","solutions":["Drain and sniff the bytes first: finfo_buffer() on stream_get_contents() to confirm actual image data","Verify upload completeness (Content-Length vs actual bytes) before decoding","Check Imagick::queryFormats() for the target format and install missing delegates","Re-fetch or re-upload the source when the body is truncated"],"exampleFix":"// before\n$image = $manager->read(fopen('php://input', 'rb')); // partial body -> generic failure\n\n// after\n$contents = file_get_contents('php://input');\nif (strlen($contents) < (int) ($_SERVER['CONTENT_LENGTH'] ?? 0)) {\n    throw new RuntimeException('Upload incomplete');\n}\n$image = $manager->read($contents);","handlingStrategy":"validation","validationCode":"$contents = stream_get_contents($stream);\n$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $contents);\nif (!str_starts_with((string) $mime, 'image/')) {\n    throw new RuntimeException('Stream did not contain image data');\n}\n$image = $manager->read($contents);","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($stream);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    $logger->warning('Stream payload undecodable: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Verify Content-Length vs actual bytes for streamed uploads before decoding","Confirm format delegates (queryFormats) exist in every environment handling streams"],"tags":["stream","decode","unsupported-format","upload"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}