gchq/CyberChef · error · OperationError

Invalid input file format.

Error message

Invalid input file format.

What it means

Thrown at the top of InvertImage.run() because isImage(input) returned falsy. Same mechanism as the other image ops, but the message text reads 'Invalid input file format.' (a wording inconsistency vs the usual 'Invalid file type.'). OperationError surfaced as step output.

Source

Thrown at src/core/operations/InvertImage.mjs:41

        this.name = "Invert Image";
        this.module = "Image";
        this.description = "Invert the colours of an image.";
        this.infoURL = "";
        this.inputType = "ArrayBuffer";
        this.outputType = "ArrayBuffer";
        this.presentType = "html";
        this.args = [];
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {byteArray}
     */
    async run(input, args) {
        if (!isImage(input)) {
            throw new OperationError("Invalid input file format.");
        }

        let image;
        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error loading image. (${err})`);
        }
        try {
            if (isWorkerEnvironment())
                self.sendStatusMessage("Inverting image...");
            image.invert();

            let imageBuffer;
            if (image.mime === "image/gif") {
                imageBuffer = await image.getBuffer(JimpMime.png);
            } else {
                imageBuffer = await image.getBuffer(image.mime);

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Confirm the input is an image with 'Detect File Type'.
  2. Ensure the prior step outputs an image ArrayBuffer.
  3. Match the op input type to the real data.
  4. Convert the source to PNG/JPEG upstream.

Example fix

// before
invertOp.run(new TextEncoder().encode('nope').buffer, []); // throws 'Invalid input file format.'
// after
import { isImage } from "src/core/lib/FileType.mjs";
if (isImage(pngBuffer) === false) throw new Error('feed an image');
invertOp.run(pngBuffer, []);
Defensive patterns

Strategy: validation

Validate before calling

import { isImage } from "src/core/lib/FileType.mjs";
const buf8 = input instanceof Uint8Array ? input : new Uint8Array(input);
if (isImage(buf8) === false) {
  throw new Error('Input is not a recognized image; cannot run invert op.');
}

Type guard

import { isImage } from "src/core/lib/FileType.mjs";
function isImageBuffer(buf) {
  const u8 = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
  return typeof isImage(u8) === 'string';
}

Prevention

When it happens

Trigger: run(input, args) receives an ArrayBuffer whose leading bytes are not a recognized image signature: text, hex, a non-image binary, or an unsupported image format.

Common situations: Pasting non-image data, wrong input-format selector, chaining after a non-image step, or a modern format (AVIF/HEIC) absent from isImage's DB.

Related errors


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