{"record":{"id":"781a0189303ac4f6","repo":"Intervention/image","slug":"invalid-limit-value-must-be-int-1-max","errorCode":null,"errorMessage":"Invalid $limit value. Must be int<1, max>","messagePattern":"Invalid \\$limit value\\. Must be int<1, max>","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Analyzers/DominantPaletteAnalyzer.php","lineNumber":55,"sourceCode":"    /**\n     * Fixed seed for deterministic results.\n     */\n    private const SEED = 1024;\n\n    /**\n     * Local RNG.\n     */\n    private Randomizer $rng;\n\n    /**\n     * Create new instance.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(protected int $limit = 8, protected ?SizeInterface $region = null)\n    {\n        if ($this->limit < 1) {\n            throw new InvalidArgumentException('Invalid $limit value. Must be int<1, max>');\n        }\n\n        $this->randomize();\n    }\n\n    /**\n     * Analyze dominant colors in given image.\n     *\n     * @throws InvalidArgumentException\n     * @throws AnalyzerException\n     */\n    public function analyze(ImageInterface $image): PaletteInterface\n    {\n        // re-seed on every run so the result only depends on the image\n        $this->randomize();\n\n        $points = $this->clusterableColors($this->collectColors($image, $this->region));\n        $clusters = $this->kMeansClustering($points); // perform K-means clustering","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Analyzers/DominantPaletteAnalyzer.php#L37-L73","documentation":"This FileNotReadableException is thrown when the directory stored in your SplFileInfo exists and the target file exists, but the PHP process lacks read permission on the directory itself (is_readable($dirname) is false). filePathFromSplFileInfoOrFail() checks directory readability before file readability, so this specifically points at the containing folder, not the file.","triggerScenarios":"ImageManager::read(new SplFileInfo('/root/photo.png')) on a /root with mode 700 while PHP runs as www-data; uploads stored in a 0700 directory owned by a deploy user while the web server user must read it; containers where the process UID differs from the volume owner; directory mode 0111 (execute-only, no read on the dir itself).","commonSituations":"CLI scripts run as root creating files/dirs that the web server user later cannot traverse or list; Docker volumes with wrong ownership; hardened production filesystems where dirs are 0700 by default; switching from mod_php to php-fpm changes the effective user.","solutions":["Grant directory read+execute access for the PHP user: chmod 755 <dirname> (or chown to the PHP-FPM user)","Confirm which user PHP runs as (posix_getuid()/posix_getpwuid()) and check ownership with ls -ld on the directory","If the permissions are intentional, move/copy the image into a directory the process can read before calling read()"],"exampleFix":"# before: directory not readable by www-data\nls -ld /var/app/uploads   # drwx------ root root\n\n# after\nchown -R www-data:www-data /var/app/uploads   # or: chmod 755 /var/app/uploads","handlingStrategy":"validation","validationCode":"$path = $splFileInfo->getPathname();\n$dirname = dirname($path);\nif (!is_dir($dirname) || !is_readable($dirname)) {\n    throw new \\RuntimeException('Storage directory missing or unreadable: ' . $dirname);\n}\n$image = $manager->read($splFileInfo);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\FileNotReadableException;\n\ntry {\n    $image = $manager->read($file);\n} catch (FileNotReadableException $e) {\n    // message says 'Directory ... is not readable': fix dir perms (chmod 755) or ownership\n}","preventionTips":["Standardize storage directories to 0755 and files to 0644 at creation time","Run CLI workers and web PHP under the same user/group, or use a shared group with group-read","Add a deployment check that verifies is_readable() on storage paths as the PHP user"],"tags":["permissions","directory-not-readable","splfileinfo","filesystem","intervention-image"],"backgroundTag":"file-permission-denied","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}