gchq/CyberChef · error · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

Contain Image scales an image to a target width/height while preserving aspect ratio (letterboxing). Before any processing it validates the input ArrayBuffer via isImage(), which sniffs magic bytes against CyberChef's recognized image MIME types. If the bytes are not a supported image, `if (!isImage(input))` throws 'Invalid file type.' This is an input-shape check distinct from the later Jimp decode step.

Source

Thrown at src/core/operations/ContainImage.mjs:109

        const resizeMap = {
            "Nearest Neighbour": ResizeStrategy.NEAREST_NEIGHBOR,
            Bilinear: ResizeStrategy.BILINEAR,
            Bicubic: ResizeStrategy.BICUBIC,
            Hermite: ResizeStrategy.HERMITE,
            Bezier: ResizeStrategy.BEZIER,
        };

        const alignMap = {
            Left: HorizontalAlign.LEFT,
            Center: HorizontalAlign.CENTER,
            Right: HorizontalAlign.RIGHT,
            Top: VerticalAlign.TOP,
            Middle: VerticalAlign.MIDDLE,
            Bottom: VerticalAlign.BOTTOM,
        };

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

        let image;
        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error loading image. (${err})`);
        }
        const originalMime = image.mime;
        try {
            if (isWorkerEnvironment())
                self.sendStatusMessage("Containing image...");
            image.contain({
                w: width,
                h: height,
                align: alignMap[hAlign] | alignMap[vAlign],
                mode: resizeMap[alg],
            });

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply a raw image ArrayBuffer in a format isImage recognizes (PNG, JPEG, BMP, GIF, etc.).
  2. If your input is encoded (hex/base64), run From Hex / From Base64 before Contain Image.
  3. Precede the operation with Detect File Type to confirm the bytes are detected as an image.

Example fix

// before: feeding hex text directly
input = "89504e470d0a..."; // string -> isImage false
// after: decode to raw bytes first
recipe: [From Hex, Contain Image]
Defensive patterns

Strategy: type-guard

Validate before calling

import { isImage } from "src/core/lib/FileType.mjs";
const buf = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
if (!isImage(buf)) {
  throw new Error("Input is not a recognized image; supply raw image bytes (decode hex/base64 first if needed).");
}

Type guard

import { isImage } from "src/core/lib/FileType.mjs";
function isImageInput(buf) {
  const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
  return isImage(bytes) !== false;
}

Prevention

When it happens

Trigger: Feeding non-image bytes (text, PDF, ZIP, executable); a truncated file whose magic bytes are missing; an empty ArrayBuffer; an image format not in isImage's signature table; feeding a string when an ArrayBuffer of raw bytes is required.

Common situations: Chaining Contain Image after an operation that emits non-image output; uploading the wrong file; forgetting to decode (e.g. feeding hex text instead of using From Hex first); using a format CyberChef's type detector doesn't recognize.

Related errors


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