{"record":{"id":"6d6d80401a1f1f38","repo":"gchq/CyberChef","slug":"invalid-input-format-please-enter-the-permissions","errorCode":null,"errorMessage":"Invalid input format.\nPlease enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.","messagePattern":"Invalid input format\\.\nPlease enter the permissions in either octal \\(e\\.g\\. 755\\) or textual \\(e\\.g\\. drwxr-xr-x\\) format\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ParseUNIXFilePermissions.mjs","lineNumber":181,"sourceCode":"\n            if (textual.length > 7) perms.ro = textual[7] === \"r\";\n            if (textual.length > 8) perms.wo = textual[8] === \"w\";\n            if (textual.length > 9) {\n                switch (textual[9]) {\n                    case \"x\":\n                        perms.eo = true;\n                        break;\n                    case \"t\":\n                        perms.eo = true;\n                        perms.sb = true;\n                        break;\n                    case \"T\":\n                        perms.sb = true;\n                        break;\n                }\n            }\n        } else {\n            throw new OperationError(\"Invalid input format.\\nPlease enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.\");\n        }\n\n        output += \"Textual representation: \" + permsToStr(perms);\n        output += \"\\nOctal representation:   \" + permsToOctal(perms);\n\n        // File type\n        if (textual) {\n            output += \"\\nFile type: \" + ftFromPerms(perms);\n        }\n\n        // setuid, setgid\n        if (perms.su) {\n            output += \"\\nThe setuid flag is set\";\n        }\n        if (perms.sg) {\n            output += \"\\nThe setgid flag is set\";\n        }\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ParseUNIXFilePermissions.mjs#L163-L199","documentation":"Parse UNIX file permissions accepts two formats: octal (1-4 digits 0-7, e.g. 755) or textual (1-10 chars from the set d,l,p,c,b,D,r,w,x,s,S,t,T,-, e.g. drwxr-xr-x). If the input starts with neither pattern it falls through to the else branch and throws. The matching uses search()===0, so the recognized pattern must appear at the very start of the (optionally whitespace-padded) input.","triggerScenarios":"Input like 'hello', '999' (8/9 are not octal digits), 'rwxrwx' with an invalid character, an embedded space such as 'drwx r-xr-x', an empty string, or data whose first characters are outside both the [0-7] and [dlpcbDrwxsStT-] sets.","commonSituations":"Pasting an ls -l line including owner/size columns instead of just the permission column; copying a Windows ACL string; trailing BOM or non-breaking spaces; typo'd symbolic permission.","solutions":["Enter octal digits 0-7 only (1 to 4 digits), e.g. 755 or 4755.","Enter a textual permission string using only d l p c b D r w x s S t T - characters, e.g. drwxr-xr-x.","Trim surrounding prose/columns from an ls -l output and keep only the 10-character permission field.","Remove BOM/non-breaking spaces and confirm UTF-8 without leading whitespace beyond what the regex allows."],"exampleFix":"// before: pasted full ls line\nrun(\"drwxr-xr-x 2 root root 4096\");\n\n// after: permission field only\nrun(\"drwxr-xr-x\");","handlingStrategy":"validation","validationCode":"function looksLikePerms(s) {\n  return /^\\s*[0-7]{1,4}\\s*$/.test(s) || /^\\s*[dlpcbDrwxsStT-]{1,10}\\s*$/.test(s);\n}\nif (!looksLikePerms(input)) throw new Error(\"Input is not octal or textual UNIX permissions\");\nreturn parseUnixFilePermissions.run(input, []);","typeGuard":"function isUnixPermissionString(s) {\n  return /^\\s*[0-7]{1,4}\\s*$/.test(s) || /^\\s*[dlpcbDrwxsStT-]{1,10}\\s*$/.test(s);\n}","tryCatchPattern":"try {\n  return parseUnixFilePermissions.run(input, []);\n} catch (e) {\n  if (e.message.startsWith(\"Invalid input format\")) {\n    // show the accepted formats to the user\n  }\n  throw e;\n}","preventionTips":["Extract only the permission column from ls -l output.","Use octal digits 0-7 only for octal mode.","Avoid 8/9 digits and spaces inside the permission field."],"tags":["filesystem","permissions","input-validation","unix"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}