gchq/CyberChef · error · OperationError

Invalid file type

Error message

Invalid file type

What it means

Thrown by RenderImage.run when the processed input (after optional Base64 decoding) is not recognized as a supported image format by isImage(). The run stage extracts/normalizes bytes before presentation; if no known image signature matches, it refuses to proceed.

Source

Thrown at src/core/operations/RenderImage.mjs:79

        // Convert input to raw bytes
        switch (inputFormat) {
            case "Hex":
                input = fromHex(input);
                break;
            case "Base64":
                // Don't trust the Base64 entered by the user.
                // Unwrap it first, then re-encode later.
                input = fromBase64(input, undefined, "byteArray");
                break;
            case "Raw":
            default:
                input = Utils.strToByteArray(input);
                break;
        }

        // Determine file type
        if (!isImage(input)) {
            throw new OperationError("Invalid file type");
        }

        return input;
    }

    /**
     * Displays the image using HTML for web apps.
     *
     * @param {byteArray} data
     * @returns {html}
     */
    async present(data) {
        if (!data.length) return "";

        let dataURI = "data:";

        // Determine file type
        const mime = isImage(data);

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure the input is a supported image (PNG/JPEG/GIF/BMP).
  2. Match the input format option to the actual encoding (Raw vs Base64).
  3. Re-acquire the full image bytes if truncation is suspected.
  4. Insert a 'From Base64'/'From Hex' step if the bytes are still encoded.

Example fix

// before
//   input format: Raw, but data is base64 text
// after
//   input format: Base64
Defensive patterns

Strategy: type-guard

Validate before calling

if (!isImage(input)) throw new Error('Input is not a supported image type');

Type guard

const isSupportedImage = buf => Boolean(isImage(buf));

Try / catch

try { op.run(input); } catch (e) { if (/Invalid file type/.test(e.message)) fixInputEncoding(); else throw e; }

Prevention

When it happens

Trigger: Supplying non-image bytes; selecting the wrong input format (e.g. 'Base64' when the input is raw bytes); corrupted/truncated image; unsupported format.

Common situations: Mismatched input format dropdown; piping a non-image operation's output into RenderImage; truncated copy-paste of image data.

Related errors


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