gchq/CyberChef · error · OperationError

Invalid input format. Please enter the permissions in either

Error message

Invalid input format.
Please enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.

What it means

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.

Source

Thrown at src/core/operations/ParseUNIXFilePermissions.mjs:181

            if (textual.length > 7) perms.ro = textual[7] === "r";
            if (textual.length > 8) perms.wo = textual[8] === "w";
            if (textual.length > 9) {
                switch (textual[9]) {
                    case "x":
                        perms.eo = true;
                        break;
                    case "t":
                        perms.eo = true;
                        perms.sb = true;
                        break;
                    case "T":
                        perms.sb = true;
                        break;
                }
            }
        } else {
            throw new OperationError("Invalid input format.\nPlease enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.");
        }

        output += "Textual representation: " + permsToStr(perms);
        output += "\nOctal representation:   " + permsToOctal(perms);

        // File type
        if (textual) {
            output += "\nFile type: " + ftFromPerms(perms);
        }

        // setuid, setgid
        if (perms.su) {
            output += "\nThe setuid flag is set";
        }
        if (perms.sg) {
            output += "\nThe setgid flag is set";
        }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Enter octal digits 0-7 only (1 to 4 digits), e.g. 755 or 4755.
  2. 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.
  3. Trim surrounding prose/columns from an ls -l output and keep only the 10-character permission field.
  4. Remove BOM/non-breaking spaces and confirm UTF-8 without leading whitespace beyond what the regex allows.

Example fix

// before: pasted full ls line
run("drwxr-xr-x 2 root root 4096");

// after: permission field only
run("drwxr-xr-x");
Defensive patterns

Strategy: validation

Validate before calling

function looksLikePerms(s) {
  return /^\s*[0-7]{1,4}\s*$/.test(s) || /^\s*[dlpcbDrwxsStT-]{1,10}\s*$/.test(s);
}
if (!looksLikePerms(input)) throw new Error("Input is not octal or textual UNIX permissions");
return parseUnixFilePermissions.run(input, []);

Type guard

function isUnixPermissionString(s) {
  return /^\s*[0-7]{1,4}\s*$/.test(s) || /^\s*[dlpcbDrwxsStT-]{1,10}\s*$/.test(s);
}

Try / catch

try {
  return parseUnixFilePermissions.run(input, []);
} catch (e) {
  if (e.message.startsWith("Invalid input format")) {
    // show the accepted formats to the user
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/6d6d80401a1f1f38. Report an issue: GitHub.