gchq/CyberChef · error · OperationError

Invalid file format.

Error message

Invalid file format.

What it means

Convert Image Format transcodes an image to a chosen target format (PNG/JPEG/BMP/etc.). It first validates the input is an image via isImage(); if the magic bytes are not a recognized image type it throws 'Invalid file format.' (note the wording differs from the other ops' 'Invalid file type').

Source

Thrown at src/core/operations/ConvertImageFormat.mjs:85

            JPEG: JimpMime.jpeg,
            PNG: JimpMime.png,
            BMP: JimpMime.bmp,
            TIFF: JimpMime.tiff,
        };

        const pngFilterMap = {
            Auto: PNGFilterType.AUTO,
            None: PNGFilterType.NONE,
            Sub: PNGFilterType.SUB,
            Up: PNGFilterType.UP,
            Average: PNGFilterType.AVERAGE,
            Paeth: PNGFilterType.PATH,
        };

        const mime = formatMap[format];

        if (!isImage(input)) {
            throw new OperationError("Invalid file format.");
        }
        let image;
        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error opening image file. (${err})`);
        }
        try {
            let buffer;
            switch (mime) {
                case JimpMime.jpeg:
                    buffer = await image.getBuffer(mime, {
                        quality: jpegQuality,
                    });
                    break;
                case JimpMime.png:
                    buffer = await image.getBuffer(mime, {
                        filterType: pngFilterMap[pngFilterType],

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply a raw image ArrayBuffer in a format isImage recognizes.
  2. If input is hex/base64 encoded, run From Hex / From Base64 first.
  3. Use Detect File Type to confirm the bytes are an image before converting.

Example fix

// before: feeding raw text
input = "some text";
// after: feed decoded image bytes
recipe: [From Base64, Convert Image Format]
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: Feeding non-image bytes; truncated file missing magic bytes; empty ArrayBuffer; a format absent from isImage's signature table; passing a string instead of raw byte ArrayBuffer.

Common situations: Wrong input file; chaining after an op that outputs non-image data; forgetting to decode hex/base64 first; using a format the type detector doesn't recognize.

Related errors


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