gchq/CyberChef · error · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

Cover Image scales an image to fill a target width/height while preserving aspect ratio (cropping overflow). It validates the input via isImage() first; non-image bytes cause `if (!isImage(input))` to throw 'Invalid file type.' This is the magic-byte input check before Jimp decoding.

Source

Thrown at src/core/operations/CoverImage.mjs:104

        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})`);
        }
        try {
            if (isWorkerEnvironment())
                self.sendStatusMessage("Covering image...");
            image.cover({
                w: width,
                h: height,
                align: alignMap[hAlign] | alignMap[vAlign],
                mode: resizeMap[alg],
            });
            let imageBuffer;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply a raw image ArrayBuffer isImage recognizes (PNG/JPEG/BMP/GIF etc.).
  2. Decode hex/base64 input with From Hex / From Base64 first.
  3. Confirm with Detect File Type before covering.

Example fix

// before: passing base64 text directly
input = "iVBORw0KGgo...";
// after
recipe: [From Base64, Cover Image]
Defensive patterns

Strategy: type-guard

Validate before calling

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

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: Non-image bytes (text/PDF/ZIP/etc.); truncated file missing magic bytes; empty ArrayBuffer; a format absent from isImage's signature table; passing a string instead of raw bytes.

Common situations: Wrong input; chaining after a non-image-producing op; forgetting to decode hex/base64; unsupported image format.

Related errors


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