{"record":{"id":"94e9e0e6df82f985","repo":"octobercms/october","slug":"invalid-selection-data","errorCode":null,"errorMessage":"Invalid selection data.","messagePattern":"Invalid selection data\\.","errorType":"validation","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/media/widgets/MediaManager.php","lineNumber":1923,"sourceCode":"    {\n        $originalFileName = basename($path);\n\n        $path = rtrim(dirname($path), '/').'/';\n        $fileName = basename($imageSrcPath);\n\n        if (\n            strpos($fileName, '..') !== false ||\n            strpos($fileName, '/') !== false ||\n            strpos($fileName, '\\\\') !== false\n        ) {\n            throw new SystemException('Invalid image file name.');\n        }\n\n        $selectionParams = ['x', 'y', 'w', 'h'];\n\n        foreach ($selectionParams as $paramName) {\n            if (!array_key_exists($paramName, $selectionData)) {\n                throw new SystemException('Invalid selection data.');\n            }\n\n            if (!is_numeric($selectionData[$paramName])) {\n                throw new SystemException('Invalid selection data.');\n            }\n\n            $selectionData[$paramName] = (int) $selectionData[$paramName];\n        }\n\n        $sessionDirectoryPath = $this->getCropSessionDirPath($cropSessionKey);\n        $fullSessionDirectoryPath = temp_path($sessionDirectoryPath);\n\n        if (!File::isDirectory($fullSessionDirectoryPath)) {\n            throw new SystemException('The image editing session is not found.');\n        }\n\n        // Find the image on the disk and resize it\n        $imagePath = $fullSessionDirectoryPath.'/'.$fileName;","sourceCodeStart":1905,"sourceCodeEnd":1941,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/media/widgets/MediaManager.php#L1905-L1941","documentation":"SystemException thrown in cropImage() (MediaManager.php:1923) when the posted selection data array lacks one of the four required keys: x, y, w, h. Each selection parameter is checked with array_key_exists before it can be cast to int, so null values also count as missing (array_key_exists passes for null, but the subsequent is_numeric check on null throws the sibling error).","triggerScenarios":"Calling the crop apply handler with selection missing a key — e.g. {x: 10, y: 10, w: 200} with no h, selection sent as a JSON string instead of a parsed array, or keys named width/height instead of w/h.","commonSituations":"Custom crop front-ends mapping UI fields to the wrong key names; serialising the selection object to a string so the server sees no array keys at all; integration code written against a different cropping API.","solutions":["Post selection as an array/object with exactly the keys x, y, w, h, all present.","Double-check the key names in the request payload (w/h, not width/height) when building custom crop UIs.","Send selection as proper form-encoded or parsed JSON data so PHP receives an array, not a scalar string."],"exampleFix":"// before\ndata: { selection: { x: 10, y: 10, w: 200, height: 150 } }\n\n// after\ndata: { selection: { x: 10, y: 10, w: 200, h: 150 } }","handlingStrategy":"validation","validationCode":"const s = selection || {};\nif (!['x', 'y', 'w', 'h'].every(k => k in s)) {\n    alert('Selection is incomplete.');\n    return;\n}\n$.request('crop', { data: { selection: s, ... } });","typeGuard":"function hasSelectionKeys(s) {\n    return !!s && typeof s === 'object'\n        && ['x', 'y', 'w', 'h'].every(k => Object.prototype.hasOwnProperty.call(s, k));\n}","tryCatchPattern":null,"preventionTips":["Send selection as a parsed object (FormData field or JSON), not a stringified blob.","Freeze the key contract (x, y, w, h) in integration tests against the crop handler."],"tags":["media-manager","crop","input-validation","selection-data"],"backgroundTag":"request-validation-failed","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}