{"record":{"id":"96b84598f95938ac","repo":"paragonie/random_compat","slug":"error-reading-from-source-device","errorCode":null,"errorMessage":"Error reading from source device","messagePattern":"Error reading from source device","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"lib/random_bytes_dev_urandom.php","lineNumber":186,"sourceCode":"\n            /**\n             * Is our result valid?\n             * @var string|bool $buf\n             */\n            if (is_string($buf)) {\n                if (RandomCompat_strlen($buf) === $bytes) {\n                    /**\n                     * Return our random entropy buffer here:\n                     */\n                    return $buf;\n                }\n            }\n        }\n\n        /**\n         * If we reach here, PHP has failed us.\n         */\n        throw new Exception(\n            'Error reading from source device'\n        );\n    }\n}\n","sourceCodeStart":168,"sourceCodeEnd":191,"githubUrl":"https://github.com/paragonie/random_compat/blob/b5d188cc9d5e02f94d2c41da23093f1ef557c5b1/lib/random_bytes_dev_urandom.php#L168-L191","documentation":"Sentinel failure of the random_compat polyfill's random_bytes() on the /dev/urandom backend: every read attempt from the entropy source failed or returned a buffer whose length did not match the requested $bytes count. It means the OS entropy device was unreadable or returned short/failed reads (e.g. /dev/urandom missing or restricted in a chroot/container), so no cryptographically secure entropy could be produced.","triggerScenarios":"Thrown at lib/random_bytes_dev_urandom.php:186 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify /dev/urandom exists and is readable by the PHP process (check open_basedir, chroot, and container device mounts)","Ensure the PHP build supports reading the device (ext/openssl or ext/mcrypt alternatives are tried before this throw; enabling them avoids the urandom path)","Upgrade PHP to 7.0+ where native random_bytes() exists and bypasses the polyfill entirely","Log the environment details and retry the operation; a transient read failure may succeed on a subsequent call"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b5d188cc9d5e02f94d2c41da23093f1ef557c5b1","analyzedAt":"2026-09-13T16:12:09.755Z","contentChangedAt":"2026-09-13T16:12:09.755Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}